]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
hwmon: (pmbus/adm1266) add clear_blackbox debugfs entry
authorAbdurrahman Hussain <abdurrahman@nexthop.ai>
Wed, 20 May 2026 22:42:40 +0000 (15:42 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 9 Jun 2026 15:23:09 +0000 (08:23 -0700)
The ADM1266 blackbox can be configured in two recording modes via
BLACKBOX_CONFIG[0]: cyclic, where the device overwrites the oldest
record once the 32-record buffer fills, and single, where it stops
recording until the buffer is cleared. Deployments that need to
preserve the full record history across multiple fault episodes
typically run in single mode and need a way to clear the buffer
after the records have been collected.

Expose a write-only debugfs file alongside sequencer_state. Writing
any data to it issues the documented clear-blackbox sub-command:
a 2-byte block-write to READ_BLACKBOX (0xDE) with payload
{0xFE, 0x00} (datasheet Rev. D).

The clear is taken under pmbus_lock because READ_BLACKBOX is also
used by adm1266_nvmem_read_blackbox() to walk records one at a
time; both paths run under pmbus_lock so the clear cannot
interleave mid-iteration and corrupt the read sequence.

Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>
Assisted-by: Claude-Code:claude-opus-4-7
Assisted-by: sashiko:gemini-3.1-pro-preview
Link: https://lore.kernel.org/r/20260520-adm1266-v5-1-c72ef1fac1ea@nexthop.ai
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/pmbus/adm1266.c

index 7f4dbc98d92a062227c0a616d3137d40a16d71a4..aa353b6b9c99353bde4843726bc3b1c5e42252cb 100644 (file)
@@ -371,6 +371,40 @@ static int adm1266_firmware_revision_read(struct seq_file *s, void *pdata)
        return 0;
 }
 
+/*
+ * Clearing the blackbox is required when the device is configured in
+ * single-recording mode (BLACKBOX_CONFIG[0] = 0): once the 32-record
+ * buffer is full the device stops recording until cleared.
+ *
+ * The clear is issued as a 2-byte block-write to READ_BLACKBOX with
+ * payload {0xFE, 0x00} per the datasheet. READ_BLACKBOX is also used
+ * by adm1266_nvmem_read_blackbox() to walk records one at a time;
+ * both paths run under pmbus_lock so the clear cannot interleave
+ * mid-iteration and corrupt the read sequence.
+ */
+static ssize_t adm1266_clear_blackbox_write(struct file *file, const char __user *ubuf,
+                                           size_t count, loff_t *ppos)
+{
+       struct i2c_client *client = file->private_data;
+       u8 payload[2] = { 0xFE, 0x00 };
+       int ret;
+
+       guard(pmbus_lock)(client);
+       ret = i2c_smbus_write_block_data(client, ADM1266_READ_BLACKBOX,
+                                        sizeof(payload), payload);
+       if (ret < 0)
+               return ret;
+
+       return count;
+}
+
+static const struct file_operations adm1266_clear_blackbox_fops = {
+       .owner = THIS_MODULE,
+       .open = simple_open,
+       .write = adm1266_clear_blackbox_write,
+       .llseek = noop_llseek,
+};
+
 static void adm1266_init_debugfs(struct adm1266_data *data)
 {
        struct dentry *root;
@@ -385,6 +419,8 @@ static void adm1266_init_debugfs(struct adm1266_data *data)
                                    adm1266_state_read);
        debugfs_create_devm_seqfile(&data->client->dev, "firmware_revision", data->debugfs_dir,
                                    adm1266_firmware_revision_read);
+       debugfs_create_file("clear_blackbox", 0200, data->debugfs_dir, data->client,
+                           &adm1266_clear_blackbox_fops);
 }
 
 static int adm1266_nvmem_read_blackbox(struct adm1266_data *data, u8 *read_buff)