@@ -83,6 +83,7 @@ struct regulator_supply_alias {
8383
8484static int _regulator_is_enabled (struct regulator_dev * rdev );
8585static int _regulator_disable (struct regulator * regulator );
86+ static int _regulator_get_error_flags (struct regulator_dev * rdev , unsigned int * flags );
8687static int _regulator_get_current_limit (struct regulator_dev * rdev );
8788static unsigned int _regulator_get_mode (struct regulator_dev * rdev );
8889static int _notifier_call_chain (struct regulator_dev * rdev ,
@@ -911,6 +912,30 @@ static ssize_t bypass_show(struct device *dev,
911912}
912913static 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