Skip to content

Commit 0f2d636

Browse files
zevweissbroonie
authored andcommitted
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: Zev Weiss <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 20078e3 commit 0f2d636

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

Documentation/ABI/testing/sysfs-class-regulator

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,84 @@ Description:
370370

371371
'unknown' means software cannot determine the state, or
372372
the reported state is invalid.
373+
374+
What: /sys/class/regulator/.../under_voltage
375+
Date: April 2022
376+
KernelVersion: 5.18
377+
Contact: Zev Weiss <[email protected]>
378+
Description:
379+
Some regulator directories will contain a field called
380+
under_voltage. This indicates if the device reports an
381+
under-voltage fault (1) or not (0).
382+
383+
What: /sys/class/regulator/.../over_current
384+
Date: April 2022
385+
KernelVersion: 5.18
386+
Contact: Zev Weiss <[email protected]>
387+
Description:
388+
Some regulator directories will contain a field called
389+
over_current. This indicates if the device reports an
390+
over-current fault (1) or not (0).
391+
392+
What: /sys/class/regulator/.../regulation_out
393+
Date: April 2022
394+
KernelVersion: 5.18
395+
Contact: Zev Weiss <[email protected]>
396+
Description:
397+
Some regulator directories will contain a field called
398+
regulation_out. This indicates if the device reports an
399+
out-of-regulation fault (1) or not (0).
400+
401+
What: /sys/class/regulator/.../fail
402+
Date: April 2022
403+
KernelVersion: 5.18
404+
Contact: Zev Weiss <[email protected]>
405+
Description:
406+
Some regulator directories will contain a field called
407+
fail. This indicates if the device reports an output failure
408+
(1) or not (0).
409+
410+
What: /sys/class/regulator/.../over_temp
411+
Date: April 2022
412+
KernelVersion: 5.18
413+
Contact: Zev Weiss <[email protected]>
414+
Description:
415+
Some regulator directories will contain a field called
416+
over_temp. This indicates if the device reports an
417+
over-temperature fault (1) or not (0).
418+
419+
What: /sys/class/regulator/.../under_voltage_warn
420+
Date: April 2022
421+
KernelVersion: 5.18
422+
Contact: Zev Weiss <[email protected]>
423+
Description:
424+
Some regulator directories will contain a field called
425+
under_voltage_warn. This indicates if the device reports an
426+
under-voltage warning (1) or not (0).
427+
428+
What: /sys/class/regulator/.../over_current_warn
429+
Date: April 2022
430+
KernelVersion: 5.18
431+
Contact: Zev Weiss <[email protected]>
432+
Description:
433+
Some regulator directories will contain a field called
434+
over_current_warn. This indicates if the device reports an
435+
over-current warning (1) or not (0).
436+
437+
What: /sys/class/regulator/.../over_voltage_warn
438+
Date: April 2022
439+
KernelVersion: 5.18
440+
Contact: Zev Weiss <[email protected]>
441+
Description:
442+
Some regulator directories will contain a field called
443+
over_voltage_warn. This indicates if the device reports an
444+
over-voltage warning (1) or not (0).
445+
446+
What: /sys/class/regulator/.../over_temp_warn
447+
Date: April 2022
448+
KernelVersion: 5.18
449+
Contact: Zev Weiss <[email protected]>
450+
Description:
451+
Some regulator directories will contain a field called
452+
over_temp_warn. This indicates if the device reports an
453+
over-temperature warning (1) or not (0).

drivers/regulator/core.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct regulator_supply_alias {
8383

8484
static int _regulator_is_enabled(struct regulator_dev *rdev);
8585
static int _regulator_disable(struct regulator *regulator);
86+
static int _regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags);
8687
static int _regulator_get_current_limit(struct regulator_dev *rdev);
8788
static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
8889
static int _notifier_call_chain(struct regulator_dev *rdev,
@@ -911,6 +912,30 @@ static ssize_t bypass_show(struct device *dev,
911912
}
912913
static DEVICE_ATTR_RO(bypass);
913914

915+
#define REGULATOR_ERROR_ATTR(name, bit) \
916+
static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \
917+
char *buf) \
918+
{ \
919+
int ret; \
920+
unsigned int flags; \
921+
struct regulator_dev *rdev = dev_get_drvdata(dev); \
922+
ret = _regulator_get_error_flags(rdev, &flags); \
923+
if (ret) \
924+
return ret; \
925+
return sysfs_emit(buf, "%d\n", !!(flags & (bit))); \
926+
} \
927+
static DEVICE_ATTR_RO(name)
928+
929+
REGULATOR_ERROR_ATTR(under_voltage, REGULATOR_ERROR_UNDER_VOLTAGE);
930+
REGULATOR_ERROR_ATTR(over_current, REGULATOR_ERROR_OVER_CURRENT);
931+
REGULATOR_ERROR_ATTR(regulation_out, REGULATOR_ERROR_REGULATION_OUT);
932+
REGULATOR_ERROR_ATTR(fail, REGULATOR_ERROR_FAIL);
933+
REGULATOR_ERROR_ATTR(over_temp, REGULATOR_ERROR_OVER_TEMP);
934+
REGULATOR_ERROR_ATTR(under_voltage_warn, REGULATOR_ERROR_UNDER_VOLTAGE_WARN);
935+
REGULATOR_ERROR_ATTR(over_current_warn, REGULATOR_ERROR_OVER_CURRENT_WARN);
936+
REGULATOR_ERROR_ATTR(over_voltage_warn, REGULATOR_ERROR_OVER_VOLTAGE_WARN);
937+
REGULATOR_ERROR_ATTR(over_temp_warn, REGULATOR_ERROR_OVER_TEMP_WARN);
938+
914939
/* Calculate the new optimum regulator operating mode based on the new total
915940
* consumer load. All locks held by caller
916941
*/
@@ -4984,6 +5009,15 @@ static struct attribute *regulator_dev_attrs[] = {
49845009
&dev_attr_max_microvolts.attr,
49855010
&dev_attr_min_microamps.attr,
49865011
&dev_attr_max_microamps.attr,
5012+
&dev_attr_under_voltage.attr,
5013+
&dev_attr_over_current.attr,
5014+
&dev_attr_regulation_out.attr,
5015+
&dev_attr_fail.attr,
5016+
&dev_attr_over_temp.attr,
5017+
&dev_attr_under_voltage_warn.attr,
5018+
&dev_attr_over_current_warn.attr,
5019+
&dev_attr_over_voltage_warn.attr,
5020+
&dev_attr_over_temp_warn.attr,
49875021
&dev_attr_suspend_standby_state.attr,
49885022
&dev_attr_suspend_mem_state.attr,
49895023
&dev_attr_suspend_disk_state.attr,
@@ -5039,6 +5073,17 @@ static umode_t regulator_attr_is_visible(struct kobject *kobj,
50395073
if (attr == &dev_attr_bypass.attr)
50405074
return ops->get_bypass ? mode : 0;
50415075

5076+
if (attr == &dev_attr_under_voltage.attr ||
5077+
attr == &dev_attr_over_current.attr ||
5078+
attr == &dev_attr_regulation_out.attr ||
5079+
attr == &dev_attr_fail.attr ||
5080+
attr == &dev_attr_over_temp.attr ||
5081+
attr == &dev_attr_under_voltage_warn.attr ||
5082+
attr == &dev_attr_over_current_warn.attr ||
5083+
attr == &dev_attr_over_voltage_warn.attr ||
5084+
attr == &dev_attr_over_temp_warn.attr)
5085+
return ops->get_error_flags ? mode : 0;
5086+
50425087
/* constraints need specific supporting methods */
50435088
if (attr == &dev_attr_min_microvolts.attr ||
50445089
attr == &dev_attr_max_microvolts.attr)

0 commit comments

Comments
 (0)