^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* sysfs entries for device PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/kobject.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/pm_qos.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/pm_wakeup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "power.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * control - Report/change current runtime PM setting of the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Runtime power management of a device can be blocked with the help of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * this attribute. All devices have one of the following two values for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * the power/control file:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * + "auto\n" to allow the device to be power managed at run time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * + "on\n" to prevent the device from being power managed at run time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * The default for all devices is "auto", which means that devices may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * subject to automatic power management, depending on their drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Changing this attribute to "on" prevents the driver from power managing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * the device at run time. Doing that while the device is suspended causes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * it to be woken up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * wakeup - Report/change current wakeup option for device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Some devices support "wakeup" events, which are hardware signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * used to activate devices from suspended or low power states. Such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * devices have one of three values for the sysfs power/wakeup file:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * + "enabled\n" to issue the events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * + "disabled\n" not to do so; or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * + "\n" for temporary or permanent inability to issue wakeup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * (For example, unconfigured USB devices can't issue wakeups.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Familiar examples of devices that can issue wakeup events include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * keyboards and mice (both PS2 and USB styles), power buttons, modems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * "Wake-On-LAN" Ethernet links, GPIO lines, and more. Some events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * will wake the entire system from a suspend state; others may just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * wake up the device (if the system as a whole is already active).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * Some wakeup events use normal IRQ lines; other use special out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * of band signaling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * It is the responsibility of device drivers to enable (or disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * wakeup signaling as part of changing device power states, respecting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * the policy choices provided through the driver model.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * Devices may not be able to generate wakeup events from all power
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * states. Also, the events may be ignored in some configurations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * for example, they might need help from other devices that aren't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * active, or which may have wakeup disabled. Some drivers rely on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * wakeup events internally (unless they are disabled), keeping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * their hardware in low power modes whenever they're unused. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * saves runtime power, without requiring system-wide sleep states.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * async - Report/change current async suspend setting for the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * Asynchronous suspend and resume of the device during system-wide power
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * state transitions can be enabled by writing "enabled" to this file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * Analogously, if "disabled" is written to this file, the device will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * suspended and resumed synchronously.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * All devices have one of the following two values for power/async:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * + "enabled\n" to permit the asynchronous suspend/resume of the device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * + "disabled\n" to forbid it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * NOTE: It generally is unsafe to permit the asynchronous suspend/resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * of a device unless it is certain that all of the PM dependencies of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * device are known to the PM core. However, for some devices this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * attribute is set to "enabled" by bus type code or device drivers and in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * that cases it should be safe to leave the default value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * autosuspend_delay_ms - Report/change a device's autosuspend_delay value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * Some drivers don't want to carry out a runtime suspend as soon as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * device becomes idle; they want it always to remain idle for some period
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * of time before suspending it. This period is the autosuspend_delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * value (expressed in milliseconds) and it can be controlled by the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * If the value is negative then the device will never be runtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * suspended.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * NOTE: The autosuspend_delay_ms attribute and the autosuspend_delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * value are used only if the driver calls pm_runtime_use_autosuspend().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * wakeup_count - Report the number of wakeup events related to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) const char power_group_name[] = "power";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) EXPORT_SYMBOL_GPL(power_group_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static const char ctrl_auto[] = "auto";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static const char ctrl_on[] = "on";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static ssize_t control_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return sysfs_emit(buf, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) dev->power.runtime_auto ? ctrl_auto : ctrl_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static ssize_t control_store(struct device * dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) const char * buf, size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) device_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (sysfs_streq(buf, ctrl_auto))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) pm_runtime_allow(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) else if (sysfs_streq(buf, ctrl_on))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) pm_runtime_forbid(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) n = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) device_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static DEVICE_ATTR_RW(control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static ssize_t runtime_active_time_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u64 tmp = pm_runtime_active_time(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) do_div(tmp, NSEC_PER_MSEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return sysfs_emit(buf, "%llu\n", tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static DEVICE_ATTR_RO(runtime_active_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static ssize_t runtime_suspended_time_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u64 tmp = pm_runtime_suspended_time(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) do_div(tmp, NSEC_PER_MSEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return sysfs_emit(buf, "%llu\n", tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static DEVICE_ATTR_RO(runtime_suspended_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static ssize_t runtime_status_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) const char *output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (dev->power.runtime_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) output = "error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) } else if (dev->power.disable_depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) output = "unsupported";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) switch (dev->power.runtime_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) case RPM_SUSPENDED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) output = "suspended";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) case RPM_SUSPENDING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) output = "suspending";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) case RPM_RESUMING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) output = "resuming";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) case RPM_ACTIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) output = "active";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return sysfs_emit(buf, "%s\n", output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static DEVICE_ATTR_RO(runtime_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static ssize_t autosuspend_delay_ms_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (!dev->power.use_autosuspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return sysfs_emit(buf, "%d\n", dev->power.autosuspend_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static ssize_t autosuspend_delay_ms_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct device_attribute *attr, const char *buf, size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) long delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (!dev->power.use_autosuspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (kstrtol(buf, 10, &delay) != 0 || delay != (int) delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) device_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) pm_runtime_set_autosuspend_delay(dev, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) device_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static DEVICE_ATTR_RW(autosuspend_delay_ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static ssize_t pm_qos_resume_latency_us_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) s32 value = dev_pm_qos_requested_resume_latency(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (value == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return sysfs_emit(buf, "n/a\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (value == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return sysfs_emit(buf, "%d\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static ssize_t pm_qos_resume_latency_us_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) const char *buf, size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) s32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (!kstrtos32(buf, 0, &value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Prevent users from writing negative or "no constraint" values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * directly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (value < 0 || value == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (value == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) } else if (sysfs_streq(buf, "n/a")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ret = dev_pm_qos_update_request(dev->power.qos->resume_latency_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return ret < 0 ? ret : n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static DEVICE_ATTR_RW(pm_qos_resume_latency_us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static ssize_t pm_qos_latency_tolerance_us_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) s32 value = dev_pm_qos_get_user_latency_tolerance(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (value < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return sysfs_emit(buf, "%s\n", "auto");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (value == PM_QOS_LATENCY_ANY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return sysfs_emit(buf, "%s\n", "any");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return sysfs_emit(buf, "%d\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static ssize_t pm_qos_latency_tolerance_us_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) const char *buf, size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) s32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (kstrtos32(buf, 0, &value) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /* Users can't write negative values directly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (value < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (sysfs_streq(buf, "auto"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) else if (sysfs_streq(buf, "any"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) value = PM_QOS_LATENCY_ANY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ret = dev_pm_qos_update_user_latency_tolerance(dev, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) return ret < 0 ? ret : n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static DEVICE_ATTR_RW(pm_qos_latency_tolerance_us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static ssize_t pm_qos_no_power_off_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return sysfs_emit(buf, "%d\n", !!(dev_pm_qos_requested_flags(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) & PM_QOS_FLAG_NO_POWER_OFF));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static ssize_t pm_qos_no_power_off_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) const char *buf, size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (kstrtoint(buf, 0, &ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (ret != 0 && ret != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) ret = dev_pm_qos_update_flags(dev, PM_QOS_FLAG_NO_POWER_OFF, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) return ret < 0 ? ret : n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static DEVICE_ATTR_RW(pm_qos_no_power_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static const char _enabled[] = "enabled";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static const char _disabled[] = "disabled";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static ssize_t wakeup_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return sysfs_emit(buf, "%s\n", device_can_wakeup(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) ? (device_may_wakeup(dev) ? _enabled : _disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static ssize_t wakeup_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) const char *buf, size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (!device_can_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (sysfs_streq(buf, _enabled))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) device_set_wakeup_enable(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) else if (sysfs_streq(buf, _disabled))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) device_set_wakeup_enable(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static DEVICE_ATTR_RW(wakeup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static ssize_t wakeup_count_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) unsigned long count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) bool enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) spin_lock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (dev->power.wakeup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) count = dev->power.wakeup->wakeup_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) spin_unlock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (!enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return sysfs_emit(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return sysfs_emit(buf, "%lu\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static DEVICE_ATTR_RO(wakeup_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static ssize_t wakeup_active_count_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) unsigned long count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) bool enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) spin_lock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (dev->power.wakeup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) count = dev->power.wakeup->active_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) spin_unlock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (!enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return sysfs_emit(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) return sysfs_emit(buf, "%lu\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static DEVICE_ATTR_RO(wakeup_active_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static ssize_t wakeup_abort_count_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) unsigned long count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) bool enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) spin_lock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (dev->power.wakeup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) count = dev->power.wakeup->wakeup_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) spin_unlock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (!enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return sysfs_emit(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return sysfs_emit(buf, "%lu\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static DEVICE_ATTR_RO(wakeup_abort_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static ssize_t wakeup_expire_count_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) unsigned long count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) bool enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) spin_lock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (dev->power.wakeup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) count = dev->power.wakeup->expire_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) spin_unlock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (!enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return sysfs_emit(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return sysfs_emit(buf, "%lu\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static DEVICE_ATTR_RO(wakeup_expire_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static ssize_t wakeup_active_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) unsigned int active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) bool enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) spin_lock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (dev->power.wakeup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) active = dev->power.wakeup->active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) spin_unlock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (!enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return sysfs_emit(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return sysfs_emit(buf, "%u\n", active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) static DEVICE_ATTR_RO(wakeup_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static ssize_t wakeup_total_time_ms_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) s64 msec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) bool enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) spin_lock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (dev->power.wakeup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) msec = ktime_to_ms(dev->power.wakeup->total_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) spin_unlock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (!enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return sysfs_emit(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return sysfs_emit(buf, "%lld\n", msec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static DEVICE_ATTR_RO(wakeup_total_time_ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static ssize_t wakeup_max_time_ms_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) s64 msec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) bool enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) spin_lock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (dev->power.wakeup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) msec = ktime_to_ms(dev->power.wakeup->max_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) spin_unlock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (!enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) return sysfs_emit(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return sysfs_emit(buf, "%lld\n", msec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static DEVICE_ATTR_RO(wakeup_max_time_ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static ssize_t wakeup_last_time_ms_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) s64 msec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) bool enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) spin_lock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (dev->power.wakeup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) msec = ktime_to_ms(dev->power.wakeup->last_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) spin_unlock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (!enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) return sysfs_emit(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) return sysfs_emit(buf, "%lld\n", msec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) static inline int dpm_sysfs_wakeup_change_owner(struct device *dev, kuid_t kuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) kgid_t kgid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (dev->power.wakeup && dev->power.wakeup->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) return device_change_owner(dev->power.wakeup->dev, kuid, kgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) static DEVICE_ATTR_RO(wakeup_last_time_ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) #ifdef CONFIG_PM_AUTOSLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static ssize_t wakeup_prevent_sleep_time_ms_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) s64 msec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) bool enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) spin_lock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (dev->power.wakeup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) msec = ktime_to_ms(dev->power.wakeup->prevent_sleep_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) spin_unlock_irq(&dev->power.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (!enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) return sysfs_emit(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) return sysfs_emit(buf, "%lld\n", msec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static DEVICE_ATTR_RO(wakeup_prevent_sleep_time_ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) #endif /* CONFIG_PM_AUTOSLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) #else /* CONFIG_PM_SLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static inline int dpm_sysfs_wakeup_change_owner(struct device *dev, kuid_t kuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) kgid_t kgid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) #ifdef CONFIG_PM_ADVANCED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) static ssize_t runtime_usage_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return sysfs_emit(buf, "%d\n", atomic_read(&dev->power.usage_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) static DEVICE_ATTR_RO(runtime_usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) static ssize_t runtime_active_kids_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) return sysfs_emit(buf, "%d\n", dev->power.ignore_children ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 0 : atomic_read(&dev->power.child_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) static DEVICE_ATTR_RO(runtime_active_kids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static ssize_t runtime_enabled_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) const char *output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) if (dev->power.disable_depth && !dev->power.runtime_auto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) output = "disabled & forbidden";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) else if (dev->power.disable_depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) output = "disabled";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) else if (!dev->power.runtime_auto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) output = "forbidden";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) output = "enabled";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) return sysfs_emit(buf, "%s\n", output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static DEVICE_ATTR_RO(runtime_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static ssize_t async_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) return sysfs_emit(buf, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) device_async_suspend_enabled(dev) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) _enabled : _disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static ssize_t async_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) const char *buf, size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) if (sysfs_streq(buf, _enabled))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) device_enable_async_suspend(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) else if (sysfs_streq(buf, _disabled))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) device_disable_async_suspend(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) static DEVICE_ATTR_RW(async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) #endif /* CONFIG_PM_SLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) #endif /* CONFIG_PM_ADVANCED_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) static struct attribute *power_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) #ifdef CONFIG_PM_ADVANCED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) &dev_attr_async.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) &dev_attr_runtime_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) &dev_attr_runtime_usage.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) &dev_attr_runtime_active_kids.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) &dev_attr_runtime_enabled.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) #endif /* CONFIG_PM_ADVANCED_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) static const struct attribute_group pm_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) .name = power_group_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) .attrs = power_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static struct attribute *wakeup_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) &dev_attr_wakeup.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) &dev_attr_wakeup_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) &dev_attr_wakeup_active_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) &dev_attr_wakeup_abort_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) &dev_attr_wakeup_expire_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) &dev_attr_wakeup_active.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) &dev_attr_wakeup_total_time_ms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) &dev_attr_wakeup_max_time_ms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) &dev_attr_wakeup_last_time_ms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) #ifdef CONFIG_PM_AUTOSLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) &dev_attr_wakeup_prevent_sleep_time_ms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) static const struct attribute_group pm_wakeup_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) .name = power_group_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) .attrs = wakeup_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static struct attribute *runtime_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) #ifndef CONFIG_PM_ADVANCED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) &dev_attr_runtime_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) &dev_attr_control.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) &dev_attr_runtime_suspended_time.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) &dev_attr_runtime_active_time.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) &dev_attr_autosuspend_delay_ms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) static const struct attribute_group pm_runtime_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) .name = power_group_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) .attrs = runtime_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) static struct attribute *pm_qos_resume_latency_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) &dev_attr_pm_qos_resume_latency_us.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) static const struct attribute_group pm_qos_resume_latency_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) .name = power_group_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) .attrs = pm_qos_resume_latency_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) static struct attribute *pm_qos_latency_tolerance_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) &dev_attr_pm_qos_latency_tolerance_us.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) static const struct attribute_group pm_qos_latency_tolerance_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) .name = power_group_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) .attrs = pm_qos_latency_tolerance_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) static struct attribute *pm_qos_flags_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) &dev_attr_pm_qos_no_power_off.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) static const struct attribute_group pm_qos_flags_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) .name = power_group_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) .attrs = pm_qos_flags_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) int dpm_sysfs_add(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /* No need to create PM sysfs if explicitly disabled. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) if (device_pm_not_required(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) rc = sysfs_create_group(&dev->kobj, &pm_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) if (!pm_runtime_has_no_callbacks(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) rc = sysfs_merge_group(&dev->kobj, &pm_runtime_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) if (device_can_wakeup(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) rc = sysfs_merge_group(&dev->kobj, &pm_wakeup_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) goto err_runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (dev->power.set_latency_tolerance) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) rc = sysfs_merge_group(&dev->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) &pm_qos_latency_tolerance_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) goto err_wakeup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) rc = pm_wakeup_source_sysfs_add(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) goto err_latency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) err_latency:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) sysfs_unmerge_group(&dev->kobj, &pm_qos_latency_tolerance_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) err_wakeup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) err_runtime:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) sysfs_unmerge_group(&dev->kobj, &pm_runtime_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) sysfs_remove_group(&dev->kobj, &pm_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) int dpm_sysfs_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (device_pm_not_required(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) rc = sysfs_group_change_owner(&dev->kobj, &pm_attr_group, kuid, kgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (!pm_runtime_has_no_callbacks(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) rc = sysfs_group_change_owner(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) &dev->kobj, &pm_runtime_attr_group, kuid, kgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (device_can_wakeup(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) rc = sysfs_group_change_owner(&dev->kobj, &pm_wakeup_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) kuid, kgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) rc = dpm_sysfs_wakeup_change_owner(dev, kuid, kgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (dev->power.set_latency_tolerance) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) rc = sysfs_group_change_owner(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) &dev->kobj, &pm_qos_latency_tolerance_attr_group, kuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) kgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) int wakeup_sysfs_add(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) int ret = sysfs_merge_group(&dev->kobj, &pm_wakeup_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) kobject_uevent(&dev->kobj, KOBJ_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) void wakeup_sysfs_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) kobject_uevent(&dev->kobj, KOBJ_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) int pm_qos_sysfs_add_resume_latency(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) return sysfs_merge_group(&dev->kobj, &pm_qos_resume_latency_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) void pm_qos_sysfs_remove_resume_latency(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) sysfs_unmerge_group(&dev->kobj, &pm_qos_resume_latency_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) int pm_qos_sysfs_add_flags(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) return sysfs_merge_group(&dev->kobj, &pm_qos_flags_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) void pm_qos_sysfs_remove_flags(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) sysfs_unmerge_group(&dev->kobj, &pm_qos_flags_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) int pm_qos_sysfs_add_latency_tolerance(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) return sysfs_merge_group(&dev->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) &pm_qos_latency_tolerance_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) void pm_qos_sysfs_remove_latency_tolerance(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) sysfs_unmerge_group(&dev->kobj, &pm_qos_latency_tolerance_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) void rpm_sysfs_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) sysfs_unmerge_group(&dev->kobj, &pm_runtime_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) void dpm_sysfs_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (device_pm_not_required(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) sysfs_unmerge_group(&dev->kobj, &pm_qos_latency_tolerance_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) dev_pm_qos_constraints_destroy(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) rpm_sysfs_remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) sysfs_remove_group(&dev->kobj, &pm_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) }