Skip to content

Commit 83bed3c

Browse files
jbrun3tgroeck
authored andcommitted
hwmon: (pmbus/core) add wp module param
Add a module parameter to force the write protection mode of pmbus chips. 4 protections modes are provided to start with: * 0: Remove the write protection * 1: Disable all writes except to the WRITE_PROTECT, OPERATION, PAGE, ON_OFF_CONFIG and VOUT_COMMAND commands * 2: Disable all writes except to the WRITE_PROTECT, OPERATION and PAGE commands * 3: Disable all writes except to the WRITE_PROTECT command Of course, if the parameter is not provided, the default write protection status of the pmbus chips is left untouched. Suggested-by: Guenter Roeck <[email protected]> Signed-off-by: Jerome Brunet <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent f404525 commit 83bed3c

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

Documentation/hwmon/pmbus-core.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,24 @@ PMBUS_VOUT_PROTECTED
387387

388388
Set if the chip VOUT_COMMAND command is protected and protection is not
389389
determined by the standard WRITE_PROTECT command.
390+
391+
Module parameter
392+
----------------
393+
394+
pmbus_core.wp: PMBus write protect forced mode
395+
396+
PMBus may come up with a variety of write protection configuration.
397+
'pmbus_core.wp' may be used if a particular write protection is necessary.
398+
The ability to actually alter the protection may also depend on the chip
399+
so the actual runtime write protection configuration may differ from
400+
the requested one. pmbus_core currently support the following value:
401+
402+
* 0: write protection removed.
403+
* 1: Disable all writes except to the WRITE_PROTECT, OPERATION,
404+
PAGE, ON_OFF_CONFIG and VOUT_COMMAND commands.
405+
* 2: Disable all writes except to the WRITE_PROTECT, OPERATION and
406+
PAGE commands.
407+
* 3: Disable all writes except to the WRITE_PROTECT command. Note that
408+
protection should include the PAGE register. This may be problematic
409+
for multi-page chips, if the chips strictly follows the PMBus
410+
specification, preventing the chip from changing the active page.

drivers/hwmon/pmbus/pmbus_core.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#define PMBUS_ATTR_ALLOC_SIZE 32
3232
#define PMBUS_NAME_SIZE 24
3333

34+
static int wp = -1;
35+
module_param(wp, int, 0444);
36+
3437
struct pmbus_sensor {
3538
struct pmbus_sensor *next;
3639
char name[PMBUS_NAME_SIZE]; /* sysfs sensor name */
@@ -2669,6 +2672,32 @@ static void pmbus_init_wp(struct i2c_client *client, struct pmbus_data *data)
26692672
{
26702673
int ret;
26712674

2675+
switch (wp) {
2676+
case 0:
2677+
_pmbus_write_byte_data(client, -1,
2678+
PMBUS_WRITE_PROTECT, 0);
2679+
break;
2680+
2681+
case 1:
2682+
_pmbus_write_byte_data(client, -1,
2683+
PMBUS_WRITE_PROTECT, PB_WP_VOUT);
2684+
break;
2685+
2686+
case 2:
2687+
_pmbus_write_byte_data(client, -1,
2688+
PMBUS_WRITE_PROTECT, PB_WP_OP);
2689+
break;
2690+
2691+
case 3:
2692+
_pmbus_write_byte_data(client, -1,
2693+
PMBUS_WRITE_PROTECT, PB_WP_ALL);
2694+
break;
2695+
2696+
default:
2697+
/* Ignore the other values */
2698+
break;
2699+
}
2700+
26722701
ret = _pmbus_read_byte_data(client, -1, PMBUS_WRITE_PROTECT);
26732702
if (ret < 0)
26742703
return;

0 commit comments

Comments
 (0)