Commit 5a13267d authored by Adam Wujek's avatar Adam Wujek

sw/patches/linux: check PMBUS_MFR_MODEL at load in monimod

Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent 1a673a47
Pipeline #3793 passed with stage
in 39 minutes and 15 seconds
From a0662987d13c464ba98f1cc5582a4d4657a8740c Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Mon, 4 Jul 2022 19:43:07 +0200
Subject: [PATCH] hwmon: (monimod) check PMBUS_MFR_MODEL at load
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/monimod.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/drivers/hwmon/pmbus/monimod.c b/drivers/hwmon/pmbus/monimod.c
index 7cf7430b0998..501bfdea5145 100644
--- a/drivers/hwmon/pmbus/monimod.c
+++ b/drivers/hwmon/pmbus/monimod.c
@@ -25,6 +25,8 @@
#define MONIMOD_FW_TYPE_BOOTLOADER 1
#define MONIMOD_FW_TYPE_MAIN 2
+#define MONIMOD_MFR_MODEL_MAIN_FW "DI/OT MoniMod"
+#define MONIMOD_MFR_MODEL_BOOTLOADER "DI/OT MoniMod (bl)"
#define MONIMOD_REG_BOOT_NEW_FW 0xD5
#define MONIMOD_REG_UPTIME_SECS 0xD7
@@ -59,15 +61,44 @@ static int monimod_probe(struct i2c_client *client,
{
int ret;
int probe_ret;
+ u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
probe_ret = pmbus_do_probe(client, id, &monimod_info);
+
+ ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, block_buffer);
+ if (ret < 0) {
+ dev_err(&client->dev, "Failed to read Manufacturer MODEL\n");
+ return ret;
+ }
+
+ block_buffer[ret] = '\0';
+ /* Check first if the monimod is in bootloader mode, to give more
+ * descriptive information */
+ if (!strcmp(block_buffer, MONIMOD_MFR_MODEL_BOOTLOADER)) {
+ dev_err(&client->dev, "Monimod in the bootloader mode, refuse "
+ "to register. Please switch to main mode.\n");
+ return -ENODEV;
+ }
+
+ /* In bootloader mode, STATUS_BYTE does not exists. Give a hint about
+ * bootloader mode (above) before failing. */
if (probe_ret < 0)
return probe_ret;
+ /* Check first if MFR model match */
+ if (ret != strlen(MONIMOD_MFR_MODEL_MAIN_FW)
+ || strcmp(block_buffer, MONIMOD_MFR_MODEL_MAIN_FW)) {
+ dev_err(&client->dev, "Unsupported Manufacturer Model. "
+ "Read %s, Expected %s\n", block_buffer,
+ MONIMOD_MFR_MODEL_MAIN_FW);
+ return -ENODEV;
+ }
ret = monimod_debugfs(client);
if (ret)
dev_warn(&client->dev, "Failed to register debugfs\n");
+ dev_info(&client->dev, "Registered Monimod\n");
+
return probe_ret;
}
--
2.17.1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment