Commit 805a5bd1 authored by Guenter Roeck's avatar Guenter Roeck
Browse files

hwmon: (pmbus) Mark lowest/average/highest/rated attributes as read-only



Writing those attributes is not supported, so mark them as read-only.

Prior to this change, attempts to write into these attributes returned
an error.

Mark boolean fields in struct pmbus_limit_attr and in struct
pmbus_sensor_attr as bit fields to reduce configuration data size.
The data is scanned only while probing, so performance is not a concern.

Fixes: 6f183d33 ("hwmon: (pmbus) Add support for peak attributes")
Reviewed-by: default avatarSanman Pradhan <psanman@juniper.net>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent bf08749a
Loading
Loading
Loading
Loading
+42 −6
Original line number Diff line number Diff line
@@ -1495,8 +1495,9 @@ static int pmbus_add_label(struct pmbus_data *data,
struct pmbus_limit_attr {
	u16 reg;		/* Limit register */
	u16 sbit;		/* Alarm attribute status bit */
	bool update;		/* True if register needs updates */
	bool low;		/* True if low limit; for limits with compare functions only */
	bool readonly:1;	/* True if the attribute is read-only */
	bool update:1;		/* True if register needs updates */
	bool low:1;		/* True if low limit; for limits with compare functions only */
	const char *attr;	/* Attribute name */
	const char *alarm;	/* Alarm attribute name */
};
@@ -1511,9 +1512,9 @@ struct pmbus_sensor_attr {
	u8 nlimit;			/* # of limit registers */
	enum pmbus_sensor_classes class;/* sensor class */
	const char *label;		/* sensor label */
	bool paged;			/* true if paged sensor */
	bool update;			/* true if update needed */
	bool compare;			/* true if compare function needed */
	bool paged:1;			/* true if paged sensor */
	bool update:1;			/* true if update needed */
	bool compare:1;			/* true if compare function needed */
	u32 func;			/* sensor mask */
	u32 sfunc;			/* sensor status mask */
	int sreg;			/* status register */
@@ -1544,7 +1545,7 @@ static int pmbus_add_limit_attrs(struct i2c_client *client,
			curr = pmbus_add_sensor(data, name, l->attr, index,
						page, 0xff, l->reg, attr->class,
						attr->update || l->update,
						false, true);
						l->readonly, true);
			if (!curr)
				return -ENOMEM;
			if (l->sbit && (info->func[page] & attr->sfunc)) {
@@ -1707,23 +1708,28 @@ static const struct pmbus_limit_attr vin_limit_attrs[] = {
	}, {
		.reg = PMBUS_VIRT_READ_VIN_AVG,
		.update = true,
		.readonly = true,
		.attr = "average",
	}, {
		.reg = PMBUS_VIRT_READ_VIN_MIN,
		.update = true,
		.readonly = true,
		.attr = "lowest",
	}, {
		.reg = PMBUS_VIRT_READ_VIN_MAX,
		.update = true,
		.readonly = true,
		.attr = "highest",
	}, {
		.reg = PMBUS_VIRT_RESET_VIN_HISTORY,
		.attr = "reset_history",
	}, {
		.reg = PMBUS_MFR_VIN_MIN,
		.readonly = true,
		.attr = "rated_min",
	}, {
		.reg = PMBUS_MFR_VIN_MAX,
		.readonly = true,
		.attr = "rated_max",
	},
};
@@ -1776,23 +1782,28 @@ static const struct pmbus_limit_attr vout_limit_attrs[] = {
	}, {
		.reg = PMBUS_VIRT_READ_VOUT_AVG,
		.update = true,
		.readonly = true,
		.attr = "average",
	}, {
		.reg = PMBUS_VIRT_READ_VOUT_MIN,
		.update = true,
		.readonly = true,
		.attr = "lowest",
	}, {
		.reg = PMBUS_VIRT_READ_VOUT_MAX,
		.update = true,
		.readonly = true,
		.attr = "highest",
	}, {
		.reg = PMBUS_VIRT_RESET_VOUT_HISTORY,
		.attr = "reset_history",
	}, {
		.reg = PMBUS_MFR_VOUT_MIN,
		.readonly = true,
		.attr = "rated_min",
	}, {
		.reg = PMBUS_MFR_VOUT_MAX,
		.readonly = true,
		.attr = "rated_max",
	},
};
@@ -1852,20 +1863,24 @@ static const struct pmbus_limit_attr iin_limit_attrs[] = {
	}, {
		.reg = PMBUS_VIRT_READ_IIN_AVG,
		.update = true,
		.readonly = true,
		.attr = "average",
	}, {
		.reg = PMBUS_VIRT_READ_IIN_MIN,
		.update = true,
		.readonly = true,
		.attr = "lowest",
	}, {
		.reg = PMBUS_VIRT_READ_IIN_MAX,
		.update = true,
		.readonly = true,
		.attr = "highest",
	}, {
		.reg = PMBUS_VIRT_RESET_IIN_HISTORY,
		.attr = "reset_history",
	}, {
		.reg = PMBUS_MFR_IIN_MAX,
		.readonly = true,
		.attr = "rated_max",
	},
};
@@ -1889,20 +1904,24 @@ static const struct pmbus_limit_attr iout_limit_attrs[] = {
	}, {
		.reg = PMBUS_VIRT_READ_IOUT_AVG,
		.update = true,
		.readonly = true,
		.attr = "average",
	}, {
		.reg = PMBUS_VIRT_READ_IOUT_MIN,
		.update = true,
		.readonly = true,
		.attr = "lowest",
	}, {
		.reg = PMBUS_VIRT_READ_IOUT_MAX,
		.update = true,
		.readonly = true,
		.attr = "highest",
	}, {
		.reg = PMBUS_VIRT_RESET_IOUT_HISTORY,
		.attr = "reset_history",
	}, {
		.reg = PMBUS_MFR_IOUT_MAX,
		.readonly = true,
		.attr = "rated_max",
	},
};
@@ -1943,20 +1962,24 @@ static const struct pmbus_limit_attr pin_limit_attrs[] = {
	}, {
		.reg = PMBUS_VIRT_READ_PIN_AVG,
		.update = true,
		.readonly = true,
		.attr = "average",
	}, {
		.reg = PMBUS_VIRT_READ_PIN_MIN,
		.update = true,
		.readonly = true,
		.attr = "input_lowest",
	}, {
		.reg = PMBUS_VIRT_READ_PIN_MAX,
		.update = true,
		.readonly = true,
		.attr = "input_highest",
	}, {
		.reg = PMBUS_VIRT_RESET_PIN_HISTORY,
		.attr = "reset_history",
	}, {
		.reg = PMBUS_MFR_PIN_MAX,
		.readonly = true,
		.attr = "rated_max",
	},
};
@@ -1980,20 +2003,24 @@ static const struct pmbus_limit_attr pout_limit_attrs[] = {
	}, {
		.reg = PMBUS_VIRT_READ_POUT_AVG,
		.update = true,
		.readonly = true,
		.attr = "average",
	}, {
		.reg = PMBUS_VIRT_READ_POUT_MIN,
		.update = true,
		.readonly = true,
		.attr = "input_lowest",
	}, {
		.reg = PMBUS_VIRT_READ_POUT_MAX,
		.update = true,
		.readonly = true,
		.attr = "input_highest",
	}, {
		.reg = PMBUS_VIRT_RESET_POUT_HISTORY,
		.attr = "reset_history",
	}, {
		.reg = PMBUS_MFR_POUT_MAX,
		.readonly = true,
		.attr = "rated_max",
	},
};
@@ -2049,18 +2076,22 @@ static const struct pmbus_limit_attr temp_limit_attrs[] = {
		.sbit = PB_TEMP_OT_FAULT,
	}, {
		.reg = PMBUS_VIRT_READ_TEMP_MIN,
		.readonly = true,
		.attr = "lowest",
	}, {
		.reg = PMBUS_VIRT_READ_TEMP_AVG,
		.readonly = true,
		.attr = "average",
	}, {
		.reg = PMBUS_VIRT_READ_TEMP_MAX,
		.readonly = true,
		.attr = "highest",
	}, {
		.reg = PMBUS_VIRT_RESET_TEMP_HISTORY,
		.attr = "reset_history",
	}, {
		.reg = PMBUS_MFR_MAX_TEMP_1,
		.readonly = true,
		.attr = "rated_max",
	},
};
@@ -2090,18 +2121,22 @@ static const struct pmbus_limit_attr temp_limit_attrs2[] = {
		.sbit = PB_TEMP_OT_FAULT,
	}, {
		.reg = PMBUS_VIRT_READ_TEMP2_MIN,
		.readonly = true,
		.attr = "lowest",
	}, {
		.reg = PMBUS_VIRT_READ_TEMP2_AVG,
		.readonly = true,
		.attr = "average",
	}, {
		.reg = PMBUS_VIRT_READ_TEMP2_MAX,
		.readonly = true,
		.attr = "highest",
	}, {
		.reg = PMBUS_VIRT_RESET_TEMP2_HISTORY,
		.attr = "reset_history",
	}, {
		.reg = PMBUS_MFR_MAX_TEMP_2,
		.readonly = true,
		.attr = "rated_max",
	},
};
@@ -2131,6 +2166,7 @@ static const struct pmbus_limit_attr temp_limit_attrs3[] = {
		.sbit = PB_TEMP_OT_FAULT,
	}, {
		.reg = PMBUS_MFR_MAX_TEMP_3,
		.readonly = true,
		.attr = "rated_max",
	},
};