From: Jerome Brunet <jbrunet@baylibre.com>
To: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
Jonathan Corbet <corbet@lwn.net>
Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
linux-doc@vger.kernel.org, Jerome Brunet <jbrunet@baylibre.com>
Subject: [PATCH 5/5] hwmon: (pmbus/core) add wp module param
Date: Fri, 20 Sep 2024 18:47:06 +0200 [thread overview]
Message-ID: <20240920-pmbus-wp-v1-5-d679ef31c483@baylibre.com> (raw)
In-Reply-To: <20240920-pmbus-wp-v1-0-d679ef31c483@baylibre.com>
Add a module parameter to force the write protection mode of pmbus chips.
2 protections modes are provided to start with:
* 0: Remove the write protection if possible
* 1: Enable full write protection if possible
Of course, if the parameter is not provided, the default write protection
status of the pmbus chips is left untouched.
Suggested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
Documentation/admin-guide/kernel-parameters.txt | 4 ++
drivers/hwmon/pmbus/pmbus_core.c | 74 ++++++++++++++++++-------
2 files changed, 59 insertions(+), 19 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 09126bb8cc9f..e41d13f46140 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4672,6 +4672,10 @@
Format: { parport<nr> | timid | 0 }
See also Documentation/admin-guide/parport.rst.
+ pmbus.wp= [HW] PMBus Chips write protection forced mode
+ Format: { 0 | 1 }
+ See drivers/hwmon/pmbus/pmbus_core.c
+
pmtmr= [X86] Manual setup of pmtmr I/O Port.
Override pmtimer IOPort with a hex value.
e.g. pmtmr=0x508
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 363def768888..ca5803bfd24a 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -31,6 +31,20 @@
#define PMBUS_ATTR_ALLOC_SIZE 32
#define PMBUS_NAME_SIZE 24
+/*
+ * PMBus write protect forced mode:
+ * PMBus may come up with a variety of write protection configuration.
+ * 'pmbus_wp' may be used if a particular write protection is necessary.
+ * The ability to actually alter the protection may also depend on the chip
+ * so the actual runtime write protection configuration may differ from
+ * the requested one. pmbus_core currently support the following value:
+ * - 0: write protection removed
+ * - 1: write protection fully enabled, including OPERATION and VOUT_COMMAND
+ * registers. Chips essentially become read-only with this.
+ */
+static int wp = -1;
+module_param(wp, int, 0444);
+
struct pmbus_sensor {
struct pmbus_sensor *next;
char name[PMBUS_NAME_SIZE]; /* sysfs sensor name */
@@ -2658,6 +2672,45 @@ static void pmbus_remove_pec(void *dev)
device_remove_file(dev, &dev_attr_pec);
}
+static void pmbus_init_wp(struct i2c_client *client, struct pmbus_data *data)
+{
+ int ret;
+
+ switch (wp) {
+ case 0:
+ _pmbus_write_byte_data(client, 0xff,
+ PMBUS_WRITE_PROTECT, 0);
+ break;
+
+ case 1:
+ _pmbus_write_byte_data(client, 0xff,
+ PMBUS_WRITE_PROTECT, PB_WP_ALL);
+ break;
+
+ default:
+ /* Ignore the other values */
+ break;
+ }
+
+ ret = _pmbus_read_byte_data(client, 0xff, PMBUS_WRITE_PROTECT);
+
+ switch (ret) {
+ case PB_WP_ALL:
+ data->flags |= PMBUS_OP_PROTECTED;
+ fallthrough;
+ case PB_WP_OP:
+ data->flags |= PMBUS_VOUT_PROTECTED;
+ fallthrough;
+ case PB_WP_VOUT:
+ data->flags |= PMBUS_WRITE_PROTECTED | PMBUS_SKIP_STATUS_CHECK;
+ break;
+
+ default:
+ /* Ignore manufacturer specific and invalid as well as errors */
+ break;
+ }
+}
+
static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
struct pmbus_driver_info *info)
{
@@ -2711,25 +2764,8 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
* faults, and we should not try it. Also, in that case, writes into
* limit registers need to be disabled.
*/
- if (!(data->flags & PMBUS_NO_WRITE_PROTECT)) {
- ret = _pmbus_read_byte_data(client, 0xff, PMBUS_WRITE_PROTECT);
-
- switch (ret) {
- case PB_WP_ALL:
- data->flags |= PMBUS_OP_PROTECTED;
- fallthrough;
- case PB_WP_OP:
- data->flags |= PMBUS_VOUT_PROTECTED;
- fallthrough;
- case PB_WP_VOUT:
- data->flags |= PMBUS_WRITE_PROTECTED | PMBUS_SKIP_STATUS_CHECK;
- break;
-
- default:
- /* Ignore manufacturer specific and invalid as well as errors */
- break;
- }
- }
+ if (!(data->flags & PMBUS_NO_WRITE_PROTECT))
+ pmbus_init_wp(client, data);
if (data->info->pages)
pmbus_clear_faults(client);
--
2.45.2
prev parent reply other threads:[~2024-09-20 16:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-20 16:47 [PATCH 0/5] hwmon: (pmbus/core) support write protected pmbus regulators Jerome Brunet
2024-09-20 16:47 ` [PATCH 1/5] regulator: core: add callback to perform runtime init Jerome Brunet
2024-09-20 16:47 ` [PATCH 2/5] regulator: core: remove machine init callback from config Jerome Brunet
2024-09-24 8:12 ` Mark Brown
2024-09-20 16:47 ` [PATCH 3/5] hwmon: (pmbus/core) allow drivers to override WRITE_PROTECT Jerome Brunet
2024-09-20 16:47 ` [PATCH 4/5] hwmon: (pmbus/core) improve handling of write protected regulators Jerome Brunet
2024-09-20 21:13 ` Guenter Roeck
2024-09-21 11:32 ` Jerome Brunet
2024-09-21 15:22 ` Guenter Roeck
2024-09-21 16:49 ` Jerome Brunet
2024-09-21 17:16 ` Guenter Roeck
2024-09-23 12:21 ` Mark Brown
2024-09-23 16:53 ` Jerome Brunet
2024-09-24 8:11 ` Mark Brown
2024-09-23 13:21 ` Mark Brown
2024-09-23 16:44 ` Guenter Roeck
2024-10-08 12:44 ` Jerome Brunet
2024-09-20 16:47 ` Jerome Brunet [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240920-pmbus-wp-v1-5-d679ef31c483@baylibre.com \
--to=jbrunet@baylibre.com \
--cc=broonie@kernel.org \
--cc=corbet@lwn.net \
--cc=jdelvare@suse.com \
--cc=lgirdwood@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®