Commit 0f2d636e authored by Zev Weiss's avatar Zev Weiss Committed by Mark Brown

regulator: core: Add error flags to sysfs attributes

If a regulator provides a get_error_flags() operation, its sysfs
attributes will now include an entry for each defined
REGULATOR_ERROR_* flag.
Signed-off-by: default avatarZev Weiss <zev@bewilderbeest.net>
Link: https://lore.kernel.org/r/20220504065252.6955-3-zev@bewilderbeest.netSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 20078e3b
...@@ -370,3 +370,84 @@ Description: ...@@ -370,3 +370,84 @@ Description:
'unknown' means software cannot determine the state, or 'unknown' means software cannot determine the state, or
the reported state is invalid. the reported state is invalid.
What: /sys/class/regulator/.../under_voltage
Date: April 2022
KernelVersion: 5.18
Contact: Zev Weiss <zev@bewilderbeest.net>
Description:
Some regulator directories will contain a field called
under_voltage. This indicates if the device reports an
under-voltage fault (1) or not (0).
What: /sys/class/regulator/.../over_current
Date: April 2022
KernelVersion: 5.18
Contact: Zev Weiss <zev@bewilderbeest.net>
Description:
Some regulator directories will contain a field called
over_current. This indicates if the device reports an
over-current fault (1) or not (0).
What: /sys/class/regulator/.../regulation_out
Date: April 2022
KernelVersion: 5.18
Contact: Zev Weiss <zev@bewilderbeest.net>
Description:
Some regulator directories will contain a field called
regulation_out. This indicates if the device reports an
out-of-regulation fault (1) or not (0).
What: /sys/class/regulator/.../fail
Date: April 2022
KernelVersion: 5.18
Contact: Zev Weiss <zev@bewilderbeest.net>
Description:
Some regulator directories will contain a field called
fail. This indicates if the device reports an output failure
(1) or not (0).
What: /sys/class/regulator/.../over_temp
Date: April 2022
KernelVersion: 5.18
Contact: Zev Weiss <zev@bewilderbeest.net>
Description:
Some regulator directories will contain a field called
over_temp. This indicates if the device reports an
over-temperature fault (1) or not (0).
What: /sys/class/regulator/.../under_voltage_warn
Date: April 2022
KernelVersion: 5.18
Contact: Zev Weiss <zev@bewilderbeest.net>
Description:
Some regulator directories will contain a field called
under_voltage_warn. This indicates if the device reports an
under-voltage warning (1) or not (0).
What: /sys/class/regulator/.../over_current_warn
Date: April 2022
KernelVersion: 5.18
Contact: Zev Weiss <zev@bewilderbeest.net>
Description:
Some regulator directories will contain a field called
over_current_warn. This indicates if the device reports an
over-current warning (1) or not (0).
What: /sys/class/regulator/.../over_voltage_warn
Date: April 2022
KernelVersion: 5.18
Contact: Zev Weiss <zev@bewilderbeest.net>
Description:
Some regulator directories will contain a field called
over_voltage_warn. This indicates if the device reports an
over-voltage warning (1) or not (0).
What: /sys/class/regulator/.../over_temp_warn
Date: April 2022
KernelVersion: 5.18
Contact: Zev Weiss <zev@bewilderbeest.net>
Description:
Some regulator directories will contain a field called
over_temp_warn. This indicates if the device reports an
over-temperature warning (1) or not (0).
...@@ -83,6 +83,7 @@ struct regulator_supply_alias { ...@@ -83,6 +83,7 @@ struct regulator_supply_alias {
static int _regulator_is_enabled(struct regulator_dev *rdev); static int _regulator_is_enabled(struct regulator_dev *rdev);
static int _regulator_disable(struct regulator *regulator); static int _regulator_disable(struct regulator *regulator);
static int _regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags);
static int _regulator_get_current_limit(struct regulator_dev *rdev); static int _regulator_get_current_limit(struct regulator_dev *rdev);
static unsigned int _regulator_get_mode(struct regulator_dev *rdev); static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
static int _notifier_call_chain(struct regulator_dev *rdev, static int _notifier_call_chain(struct regulator_dev *rdev,
...@@ -911,6 +912,30 @@ static ssize_t bypass_show(struct device *dev, ...@@ -911,6 +912,30 @@ static ssize_t bypass_show(struct device *dev,
} }
static DEVICE_ATTR_RO(bypass); static DEVICE_ATTR_RO(bypass);
#define REGULATOR_ERROR_ATTR(name, bit) \
static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \
char *buf) \
{ \
int ret; \
unsigned int flags; \
struct regulator_dev *rdev = dev_get_drvdata(dev); \
ret = _regulator_get_error_flags(rdev, &flags); \
if (ret) \
return ret; \
return sysfs_emit(buf, "%d\n", !!(flags & (bit))); \
} \
static DEVICE_ATTR_RO(name)
REGULATOR_ERROR_ATTR(under_voltage, REGULATOR_ERROR_UNDER_VOLTAGE);
REGULATOR_ERROR_ATTR(over_current, REGULATOR_ERROR_OVER_CURRENT);
REGULATOR_ERROR_ATTR(regulation_out, REGULATOR_ERROR_REGULATION_OUT);
REGULATOR_ERROR_ATTR(fail, REGULATOR_ERROR_FAIL);
REGULATOR_ERROR_ATTR(over_temp, REGULATOR_ERROR_OVER_TEMP);
REGULATOR_ERROR_ATTR(under_voltage_warn, REGULATOR_ERROR_UNDER_VOLTAGE_WARN);
REGULATOR_ERROR_ATTR(over_current_warn, REGULATOR_ERROR_OVER_CURRENT_WARN);
REGULATOR_ERROR_ATTR(over_voltage_warn, REGULATOR_ERROR_OVER_VOLTAGE_WARN);
REGULATOR_ERROR_ATTR(over_temp_warn, REGULATOR_ERROR_OVER_TEMP_WARN);
/* Calculate the new optimum regulator operating mode based on the new total /* Calculate the new optimum regulator operating mode based on the new total
* consumer load. All locks held by caller * consumer load. All locks held by caller
*/ */
...@@ -4984,6 +5009,15 @@ static struct attribute *regulator_dev_attrs[] = { ...@@ -4984,6 +5009,15 @@ static struct attribute *regulator_dev_attrs[] = {
&dev_attr_max_microvolts.attr, &dev_attr_max_microvolts.attr,
&dev_attr_min_microamps.attr, &dev_attr_min_microamps.attr,
&dev_attr_max_microamps.attr, &dev_attr_max_microamps.attr,
&dev_attr_under_voltage.attr,
&dev_attr_over_current.attr,
&dev_attr_regulation_out.attr,
&dev_attr_fail.attr,
&dev_attr_over_temp.attr,
&dev_attr_under_voltage_warn.attr,
&dev_attr_over_current_warn.attr,
&dev_attr_over_voltage_warn.attr,
&dev_attr_over_temp_warn.attr,
&dev_attr_suspend_standby_state.attr, &dev_attr_suspend_standby_state.attr,
&dev_attr_suspend_mem_state.attr, &dev_attr_suspend_mem_state.attr,
&dev_attr_suspend_disk_state.attr, &dev_attr_suspend_disk_state.attr,
...@@ -5039,6 +5073,17 @@ static umode_t regulator_attr_is_visible(struct kobject *kobj, ...@@ -5039,6 +5073,17 @@ static umode_t regulator_attr_is_visible(struct kobject *kobj,
if (attr == &dev_attr_bypass.attr) if (attr == &dev_attr_bypass.attr)
return ops->get_bypass ? mode : 0; return ops->get_bypass ? mode : 0;
if (attr == &dev_attr_under_voltage.attr ||
attr == &dev_attr_over_current.attr ||
attr == &dev_attr_regulation_out.attr ||
attr == &dev_attr_fail.attr ||
attr == &dev_attr_over_temp.attr ||
attr == &dev_attr_under_voltage_warn.attr ||
attr == &dev_attr_over_current_warn.attr ||
attr == &dev_attr_over_voltage_warn.attr ||
attr == &dev_attr_over_temp_warn.attr)
return ops->get_error_flags ? mode : 0;
/* constraints need specific supporting methods */ /* constraints need specific supporting methods */
if (attr == &dev_attr_min_microvolts.attr || if (attr == &dev_attr_min_microvolts.attr ||
attr == &dev_attr_max_microvolts.attr) attr == &dev_attr_max_microvolts.attr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment