From nobody Sun May 24 22:45:50 2026 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3B9A313293 for ; Wed, 20 May 2026 22:42:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779316968; cv=none; b=nMJmzyo3PjJ7K3kYj6TV7CIrUuQnQj5pvG0D6369QEQLD/vgNl2Y5aqbL3E+XfR2uSIz1c8m0gfaOKmt91ym1IGA9X9UNOLUtDWMffX77RwKFw/7xvAX9U092JdmGww0Hsr5xsB3KOcoZWOkO1SHupG7jOURdMokzCjyin8YdK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779316968; c=relaxed/simple; bh=cjNAvb2CUF+16uCtjzoFz5BSRbJ34KEoz9HHaGrsXOM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oore+2pAGMq+Y1ToBL99yAoBfOKZZM64vUhHmT8569x23MsYP3/uANrC9yZg2Y5wuYUI6ZRgGJU69JpZzpEl+T7n6w2KeG1gvOuLZFX7afurxc3yrg7pCnzHc0mMVDAdB/QKEUInB4zS2T8C+TnaJeNiPjkHfqeTpXBapgWtSRU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=aR8m3nPC; arc=none smtp.client-ip=74.125.82.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="aR8m3nPC" Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-3025d725a05so13728876eec.1 for ; Wed, 20 May 2026 15:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1779316966; x=1779921766; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=/ics9Q+j7sZbOf6yU1DWNTIFuD49pEL8OYqz+Aj7MIg=; b=aR8m3nPCCq0Ca+U1O3heYXOxdsnyScToT/KLkjcnh7z67PqMrt3Nbz+QosJqSelJvS sCOv531I/gTUsKNZYyZKKK32948qaexb5Hk5ZIlnKAB7Va7zovJGqNZFvgVrkQI6fUHL U6IE2igS3cu9le8XYUqKRqOer4Bed9KvW68CU+13I5cpioJLWI888E0YJRKTV6qsTu5u 8ftYXy6bkj6Wabfxzjn92dQwpXhr6eXWUBq5V+MWfcO0ntdIYH5mNVFLNTqptgAxTL0G +17DfzxFjnaUHvdAJyRcBACXCS6YkNFNGlwB/Gj3A6gLy4xnAfINogPTQCcRMbxc3xgw AGqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779316966; x=1779921766; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=/ics9Q+j7sZbOf6yU1DWNTIFuD49pEL8OYqz+Aj7MIg=; b=N+bKEXpDMk1mELpq0h75sUpyCgK/A5SUyFGJqZhUPlo7UA00yEetBY/9ZaMUzDsswd SujEX45dBw54XU7xSi9lzaeQgcVLkxiHXaPUQrFRgRe3VpYTb+YZbRERPSkXQnh4cFoU 3Id2PYduvI0scG69vItU81mojPYwheJfMyRyXY9GUlQtOky6gZJrwFK0eAQ17EsfE6m3 SW3i6KxBvAwTnwvV/q9dadMYIsDM6R4xOQoK6N8M9Rn5SLDggiBxImrKDjv4Pi1zrPXl aQio9eIgoMr2ZZUimuYgFB8CpTQwCcENKOeylY1i4zsqbU2gd6UnICrpjMGKwDJ8Z1IX Ym+Q== X-Forwarded-Encrypted: i=1; AFNElJ+xMRvT1LQU9ZUHXG61ujfrf9nDeeH7x4dUP+yaToyNk8Zh+bak7j0Jsr4s53gjej+4zLive4JlvE/xuVI=@vger.kernel.org X-Gm-Message-State: AOJu0YyyU7F6Uk6BgeuHv46TrtiKK/kAPQRgaFW+6PV5Um9ot98PuErt Zg3Su9I2h8/ZSoJR5hDr0caLKeiQX9BUSqXPoQ1v2nCHuax1bFyGuj/nX0w049Cy/Rk+XH6yrJK C7si6 X-Gm-Gg: Acq92OH7dlU9YEJwytd4ApFImeACj7G4mtwZIMsJyk993wozTkgw6uAZbBnTTNQn7kR 1cqM98+XUs661dOW2iZ/l9a+odHUayk6pVSJm+TS5ZY2ditGIA9xqT0oRUPjuzf9IZJH2WxTFAN g5clzU0LhIxoMhX61oxmgePOuKbtwo/6yzWYWsKNwMTFM1isouJsyPURbCQu6pwv5VswZfHTHhf ubKeqUE7t7qis7J0AGqcU59uV0NbCkcb3DbGSH+3qxxf/xykOug2pBiOWqqP8Amh98jmSh9T6aU zRJoCN6R6Z7UsDYcfztlu7DMeZE/kMw+lmnmHImusLwNJ0ef4Kh1gEdEaiHRHdGeOr4ki635kga GMTSYxL5W4fxkGYm4mOfdp/sk5PR/xOHosQdzYxcc2kYGT1oqXvdNMLNiqWMAabORq5pWwtRMZ9 lHoVJbGCfBjUzKSRCiBW4eD8/o6w== X-Received: by 2002:a05:7300:e787:b0:2f5:5dd3:1fd8 with SMTP id 5a478bee46e88-3042f476c1cmr326200eec.8.1779316966028; Wed, 20 May 2026 15:42:46 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30293e2e3c0sm25575614eec.3.2026.05.20.15.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 15:42:45 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 20 May 2026 15:42:40 -0700 Subject: [PATCH v5 1/3] hwmon: (pmbus/adm1266) add clear_blackbox debugfs entry Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260520-adm1266-v5-1-c72ef1fac1ea@nexthop.ai> References: <20260520-adm1266-v5-0-c72ef1fac1ea@nexthop.ai> In-Reply-To: <20260520-adm1266-v5-0-c72ef1fac1ea@nexthop.ai> To: Guenter Roeck , Alexandru Tachici Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779316964; l=3224; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=cjNAvb2CUF+16uCtjzoFz5BSRbJ34KEoz9HHaGrsXOM=; b=AyT6TEV99hU6oaqBdPFXheLN/q5cHA1fqgPyPVVpOXmhPUtCv+T7tjOJ5ewkefg0XalIHp0j1 dTvUJs344DNCbjlrqzd6UBxi+JeQ0NMGUz2HPDGhmHEynwlcKSpaIGE X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= 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 Assisted-by: Claude-Code:claude-opus-4-7 Assisted-by: sashiko:gemini-3.1-pro-preview --- drivers/hwmon/pmbus/adm1266.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c index aadca716fe7f..e9d9cdb11e67 100644 --- a/drivers/hwmon/pmbus/adm1266.c +++ b/drivers/hwmon/pmbus/adm1266.c @@ -370,6 +370,40 @@ static int adm1266_firmware_revision_read(struct seq_f= ile *s, void *pdata) return 0; } =20 +/* + * Clearing the blackbox is required when the device is configured in + * single-recording mode (BLACKBOX_CONFIG[0] =3D 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 =3D file->private_data; + u8 payload[2] =3D { 0xFE, 0x00 }; + int ret; + + guard(pmbus_lock)(client); + ret =3D 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 =3D { + .owner =3D THIS_MODULE, + .open =3D simple_open, + .write =3D adm1266_clear_blackbox_write, + .llseek =3D noop_llseek, +}; + static void adm1266_init_debugfs(struct adm1266_data *data) { struct dentry *root; @@ -384,6 +418,8 @@ static void adm1266_init_debugfs(struct adm1266_data *d= ata) 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->clie= nt, + &adm1266_clear_blackbox_fops); } =20 static int adm1266_nvmem_read_blackbox(struct adm1266_data *data, u8 *read= _buff) --=20 2.53.0 From nobody Sun May 24 22:45:50 2026 Received: from mail-dl1-f47.google.com (mail-dl1-f47.google.com [74.125.82.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D84343438A3 for ; Wed, 20 May 2026 22:42:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779316970; cv=none; b=M+eml0ticIr3e4fvf+q4VB22sO6gZdVKUAJXfx8Nolc0p2tMQiVufutboWQFkXeFNJJlwuKtz4FT3ukAUN10GG0ujl98WyhY/xH5CcadOcjV/+7Ca57HTwX5mTu2kwDd80DVvJrrhigq4WoGraIY255YQFCS9j0UZDgQNhRh4V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779316970; c=relaxed/simple; bh=xg2ajx8NOtci7WUfRgy6qk4gKyeLg00eUNa5NfBq5fI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=K9GPnVQ0AJZRr+447FyWxpzwMV9iyj1DM4tB4Nc9Ft55uY7eeMwDKoqpOUiQz0UWErxIV4aqqoM4EzWjx/STBgxtOaTIhQeacfcqJPvxxcuv9kxK+vrFEUnZhLJvxhb/r6NMIj/hjtLyyC3XJcwHMjdMtTulZXeLumoZaRxxt5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=BScPc5pr; arc=none smtp.client-ip=74.125.82.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="BScPc5pr" Received: by mail-dl1-f47.google.com with SMTP id a92af1059eb24-1332772f6b3so7131971c88.1 for ; Wed, 20 May 2026 15:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1779316967; x=1779921767; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=s1ZyPt3QPoTJXeeOiq1m7CepxDNls2APDNcrwHqN3BY=; b=BScPc5prJ8U4vbczdrPe+/RNIaNcjsflQ9dDLjx/FnRo9ln4C/0ptPPoV9F3p0Oyel AsyTOjwTU/cruv4zsxARmCCmodOqTQwB9tKCQUDbGqtoIw10N+5VQDnd52I6D87bKw2+ prLlD6+m++zNOigkaUXBhyXGMHCviFal/TfsE7iNmTB2apjhPCR1SVmqa90gYAqeXfu1 OlIgHtCy1pJuPfCOlV3IQMJh1Ff/OnA8GuesQI5G7bC9ErVGai1725yyXCAxuDmTGBn/ PGQqadKGSW25EXVEhmINPLQsjXxDvM1arMD431QaUT8PnxKH0vs2lEw4lUO47rhUi+t7 GAIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779316967; x=1779921767; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=s1ZyPt3QPoTJXeeOiq1m7CepxDNls2APDNcrwHqN3BY=; b=pByex5FGnsw6ztLkK6e5gsIrVShi4V1ZzRLZRIXm2PqDYckA2O1a2FBmYmivKNqgg/ ySbHZGm0oyvkrTQtT3Fz5h4+06JyQoFKRkE/UiVljR332lyck9MZiXfXqqNJWuzlwZsG hhrRLGz90UmHDJMbplGWFWYu16ul6Ch/dLMlQaWoAXjqOTcZ0pGxRhEN0gGKPaj1gm4o LXSR5nHsQISl2FYyHe4WquJ+aOAhVstxyBS4SdVbfrQmVquaUOjOUy5T1WGayl12sGOq bFwBxXyjCcqxSeSXkAOFHoyv1vMCyxOYzqOgRDPETc0P8BR07zS1ljFpTq1N9L8s7H72 FT3Q== X-Forwarded-Encrypted: i=1; AFNElJ8rY4gZ6m+0EI0Ix2bMNZlgfknejwX89zocu5K1Q90rQNjIiuadSyq2OCX988zImHq5m2eyLo4YQzbfGkE=@vger.kernel.org X-Gm-Message-State: AOJu0YwNnorS4TavIVuD97ESnDegX6t9mmjGwEGlcVve/3/OSx/beviV wVCmASVLJf4bvZOPHGzmVp2KLN3KOnYPhp50ttgMsOJ29X7ddEPHR+SAqSGvmsvQQGz3593LJ+d mAZ1p X-Gm-Gg: Acq92OG8QAdFYybv+VkldopewpzBZTjcSPldqQtBYlHP0KZ8yq1+1aS4tiE17/QUvtv qYJKtv2d+zckvE45d0KUgzdFyuTZdJxnk3+zdSSIAp4dActjGnmXHuuxvwzkH1VZ/KsPks6SGfH Vg6QW+NX1GrnFs/JX4EKWJS290cOxun8JZXjFKgh3ZO8Bl6z3RMGJNFW8SwjVR/deOQZ0CRsqu5 ggeC3NbcKy0GJxaGC1ud1rXaQg4LaeF5wMTfiZZrhN7cmMlVE9tzDUMDwPq7VK5aTfEVyvlQfLt GKhYDdL65qA7OLVfvmZsdp/MU/KsZFPBVUqwnEC/BAOheJ47VxjbfFPYvJnRGiF4zVAh/ovts7A 8ijg+qAHglEcIrxqnhNiz2CVgMCBffNYI7PvK1XtQx4ZsChJ7p7qeM9iz8HsrjJ14lQOR6uTEUQ Iz3eQB+IW8BBsteWYjGkaoA3euaw== X-Received: by 2002:a05:7300:bc03:b0:2da:1a81:588 with SMTP id 5a478bee46e88-3042f5a49edmr320107eec.14.1779316966704; Wed, 20 May 2026 15:42:46 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30293e2e3c0sm25575614eec.3.2026.05.20.15.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 15:42:46 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 20 May 2026 15:42:41 -0700 Subject: [PATCH v5 2/3] hwmon: (pmbus/adm1266) add powerup_counter debugfs entry Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260520-adm1266-v5-2-c72ef1fac1ea@nexthop.ai> References: <20260520-adm1266-v5-0-c72ef1fac1ea@nexthop.ai> In-Reply-To: <20260520-adm1266-v5-0-c72ef1fac1ea@nexthop.ai> To: Guenter Roeck , Alexandru Tachici Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779316964; l=3153; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=xg2ajx8NOtci7WUfRgy6qk4gKyeLg00eUNa5NfBq5fI=; b=7zkYU5FMlsDaEk/xelNosT8Vq1edXxOc4/qoOxMsk0ajogDvHpzbFHcaWKbC7vsTB1OqhEAeP ap3BJT/tinqAJC1SNRrD2u1JHJyKdKqX3O+KgQp0iA9d9h3cBcDGzsZ X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= The ADM1266 maintains a 16-bit non-volatile POWERUP_COUNTER register (0xE4, datasheet Rev. D, Table 93) that increments on every power cycle and cannot be reset by the host. Each blackbox record already embeds the counter at record time, so the standalone live value is primarily useful for matching a captured record back to the boot it came from when correlating logs. Expose it as a read-only debugfs file alongside sequencer_state. The block-read returns two payload bytes in little-endian order. Take pmbus_lock around the block-read so the access serialises with any pmbus_core sequence that sets PAGE on the device. Without it, a PAGE write from another thread could interleave between a PAGE set and a paged read elsewhere in the driver and corrupt either side's view of the device state machine. Signed-off-by: Abdurrahman Hussain Assisted-by: Claude-Code:claude-opus-4-7 Assisted-by: sashiko:gemini-3.1-pro-preview --- drivers/hwmon/pmbus/adm1266.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c index e9d9cdb11e67..b6820415d99e 100644 --- a/drivers/hwmon/pmbus/adm1266.c +++ b/drivers/hwmon/pmbus/adm1266.c @@ -28,6 +28,7 @@ #define ADM1266_READ_BLACKBOX 0xDE #define ADM1266_SET_RTC 0xDF #define ADM1266_GPIO_CONFIG 0xE1 +#define ADM1266_POWERUP_COUNTER 0xE4 #define ADM1266_BLACKBOX_INFO 0xE6 #define ADM1266_PDIO_STATUS 0xE9 #define ADM1266_GPIO_STATUS 0xEA @@ -370,6 +371,32 @@ static int adm1266_firmware_revision_read(struct seq_f= ile *s, void *pdata) return 0; } =20 +/* + * POWERUP_COUNTER (0xE4) is a 2-byte little-endian non-volatile counter + * that increments on every device power cycle (datasheet Rev. D, Table + * 93). It saturates at 65535 and cannot be reset by the host. Each + * blackbox record embeds the counter value at record time, so this live + * read is mainly useful for matching a record back to its boot. + */ +static int adm1266_powerup_counter_read(struct seq_file *s, void *pdata) +{ + struct device *dev =3D s->private; + struct i2c_client *client =3D to_i2c_client(dev); + u8 buf[I2C_SMBUS_BLOCK_MAX]; + int ret; + + guard(pmbus_lock)(client); + ret =3D i2c_smbus_read_block_data(client, ADM1266_POWERUP_COUNTER, buf); + if (ret < 0) + return ret; + if (ret !=3D 2) + return -EIO; + + seq_printf(s, "%u\n", buf[0] | (buf[1] << 8)); + + return 0; +} + /* * Clearing the blackbox is required when the device is configured in * single-recording mode (BLACKBOX_CONFIG[0] =3D 0): once the 32-record @@ -418,6 +445,8 @@ static void adm1266_init_debugfs(struct adm1266_data *d= ata) adm1266_state_read); debugfs_create_devm_seqfile(&data->client->dev, "firmware_revision", data= ->debugfs_dir, adm1266_firmware_revision_read); + debugfs_create_devm_seqfile(&data->client->dev, "powerup_counter", data->= debugfs_dir, + adm1266_powerup_counter_read); debugfs_create_file("clear_blackbox", 0200, data->debugfs_dir, data->clie= nt, &adm1266_clear_blackbox_fops); } --=20 2.53.0 From nobody Sun May 24 22:45:50 2026 Received: from mail-dy1-f181.google.com (mail-dy1-f181.google.com [74.125.82.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 868F43C1410 for ; Wed, 20 May 2026 22:42:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779316971; cv=none; b=bD4Gwib8n0RmvDw127kWo1cUVTURqhpxGvxS16lQCasTOeWZ2nS2ZMiLzRHAUTbEi9hyJv5zLuKtBPEchCn9gGMdMrhFm0pYV+Qcr0CkAox7K17afEu86p+jVJHVxCAB5clzkHg/82qtELHxWxjqYQKcIuHkUyjOOIPG/6rLQ1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779316971; c=relaxed/simple; bh=kpxSi7jWVavvVYPl7UpO3wQxVoIBWssz+1mWqAlbFsI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r2FX94Xm6hW4o0Cp5wsaUPwFA/mRRRyYEJdq5Fdad40Awar/v9Bjimm+6eLjAkXgQBY7TJ9p9hCmpoeqJ+Eu3nsg3+IKTDjwme6PelWm596WltYAZxOF7lc++rS0ZRb6OqTah5ZAG1owCD/mfGLrpfQESIfpftKHrdd1PfxWy9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=afekD03z; arc=none smtp.client-ip=74.125.82.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="afekD03z" Received: by mail-dy1-f181.google.com with SMTP id 5a478bee46e88-2f0d3e07e30so18700346eec.0 for ; Wed, 20 May 2026 15:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1779316967; x=1779921767; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=naRx/tcvV4ICyuu1T2WRfyD3IYJbZPSfRXyBAbde4No=; b=afekD03znZEXVhmqQbyTwGAsxL5tAKeBC+x2xTclWJ++SHJy9WxaIBKVf2hPF51Te0 FRaGInRCfgtgPhTC4NCd2DbWA2gCdBP/0lIt5P01GLSHRxTgfBMd9cgyq3bgttI/upuT bMZg5fwof3bO1daySlMqtF09fFOuwLVC/bfZFB3hXDF3+gr+Ovzk6K3WzVSF4gVnD+iz Tr6v8/uEdr8Qo3HuAfFeoWA73faGsI4e44dPlUffXC7gYcXs9E7+nms5qmw0Qv5OY4on ZdzMeYHRE+1Zf2ZsR0eCBGEll8shPONQCoRCogbhn/SePgSIsOiAgU2ExedHrullr4LC ZuYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779316967; x=1779921767; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=naRx/tcvV4ICyuu1T2WRfyD3IYJbZPSfRXyBAbde4No=; b=fGcAgtb/9wp4LV+tfY36c6qLBSvcPL+SI2z08WjI1xPl+BTryEh5APb2WZ92OqJ+hi DkAqx7KYg/XglyIJNMYHK/9rN19Q/kJX3OswKst5xK4P5Jqlp3sVIELMwhdUrIXSwaZa cq5md9KVpj78Lxa1LwyAiAiSSJ7qbvp/xYevOtR4bnvhmuKEp51Qm3lmlZy93EC79t8E BfsiCBb3+rGWrffPP81PlmsmuUO8FI+50Kont39UsTeD2uYBVRsMeUclRLRYmVeAgzpx A+3+pHWDjS3AOOhjQqffF2Zg/gFRvCnDsJ62jzqFpLykYF3HNwWDEad6pf+tQGJ2+e/o JHAg== X-Forwarded-Encrypted: i=1; AFNElJ/2owTCFsYuVkUgBou5vLH8QObFMyZMJLJBUq3sJapcxyPXyVrO+hwdrJKsBVNmDEB9okG1YgR+rybU984=@vger.kernel.org X-Gm-Message-State: AOJu0YxDxmB+WHUp9A5NeyXNLW2UQxKqzlDFy82kYGqUFGzTOJJAdwYR OJP+DlxaDa9eQIJNccOIofZCHWXuffuYc6GOeK6CJ/EbmPbBk7L/pE9BuFLxm9Lix3ioY3flsuz 1GHGX X-Gm-Gg: Acq92OFRdKtnO3GyEL5lxyrB+s+9xINIsAIFe5hyp6OYV7dxYaRKyqitjwJTt31NLm+ adRhid6a+gJaO/rSV7SnJS3WAhXBHwsJxNC1AgWITZkyTTjnoQFcUXeUE5do1+yq15fRkWDXyNb B+FQkNc1FfGXizPgSFCtoCXdOLqNiVEs0FawYWog1CotsefO5L9VhfMSndtUXLpiDXhfsdzdV6o 5zEb+AUDgrGejKFpTJlLrZcwQ93SE5KYBNt92GieuWU+OpUmbLa/1rdu3E8NUI8lEJ2VpBRlky0 EnaVjCi2ydcHDdVb8yZ8HyGnHONRNEBH3fA1wxJIjKukddjhw3Q3DD40+4OLpNTttHjrrk+vbph 2pW9SlvM6V6zY+xr8JJDV9NF20K6FbhftT6MqQ4MtGvDYByEM/IX2m9tNAVrHbxJilB8Jw/p6WD PSSshlQU1sBNQLDzCEEQzc/cyF7PWESno+UsdfE5QnYrwkpsA= X-Received: by 2002:a05:7301:eac:b0:2e7:5737:8364 with SMTP id 5a478bee46e88-3042f487b62mr329241eec.15.1779316967428; Wed, 20 May 2026 15:42:47 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30293e2e3c0sm25575614eec.3.2026.05.20.15.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 15:42:47 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 20 May 2026 15:42:42 -0700 Subject: [PATCH v5 3/3] hwmon: (pmbus/adm1266) add rtc debugfs entry Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260520-adm1266-v5-3-c72ef1fac1ea@nexthop.ai> References: <20260520-adm1266-v5-0-c72ef1fac1ea@nexthop.ai> In-Reply-To: <20260520-adm1266-v5-0-c72ef1fac1ea@nexthop.ai> To: Guenter Roeck , Alexandru Tachici Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779316964; l=6006; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=kpxSi7jWVavvVYPl7UpO3wQxVoIBWssz+1mWqAlbFsI=; b=eu91dOsfcAYyS/vtzcaFMNWJeDuPidBQMTmJeDjrm1LIgKginIDDJIXb2pFW3Zmjnwf81u66t uRIm7u8pP/wCk5BdUKLM4zmE7ygsD2KjYDRX+c7f715S2ekhPba/RCQ X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= The driver seeds the chip's SET_RTC register once at probe with ktime_get_real_seconds(). Over a long uptime the chip's internal seconds counter drifts away from the host's wall-clock time, so the timestamp embedded in each blackbox record stops being meaningful in wall-clock terms. The datasheet recommends that the host periodically resynchronise the counter to address this; today the driver has no userspace-facing knob for that. Expose SET_RTC via an rtc debugfs file alongside the other adm1266 debugfs entries: read -- returns the chip's current SET_RTC seconds counter, so userspace can observe how far the chip has drifted from host wall-clock without writing anything. write -- the kernel re-reads ktime_get_real_seconds() itself and pushes it to the chip. The write payload is ignored; userspace does not get to supply its own timestamp value, so there is no way for it to push a wrong time into the chip. A small userspace agent (chrony hook, systemd-timesyncd dispatch script, or a periodic cron job) can write to this file to keep the chip's counter aligned with wall-clock across long uptimes. Both the read and write paths take pmbus_lock to serialise against the pmbus_core's own PAGE+register sequences and against the other adm1266 debugfs accessors that already run under the same lock. While at it, drop the now-redundant adm1266_set_rtc() probe-time helper. The new adm1266_rtc_set() callback does exactly the same byte-packing and write; probe just calls adm1266_rtc_set(client, 0) (the ignored @val argument) after pmbus_do_probe() so the pmbus_lock acquired by the new helper has a live mutex to take. Signed-off-by: Abdurrahman Hussain Assisted-by: Claude-Code:claude-opus-4-7 Assisted-by: sashiko:gemini-3.1-pro-preview --- drivers/hwmon/pmbus/adm1266.c | 90 +++++++++++++++++++++++++++++++++------= ---- 1 file changed, 69 insertions(+), 21 deletions(-) diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c index b6820415d99e..dcf2b038cd37 100644 --- a/drivers/hwmon/pmbus/adm1266.c +++ b/drivers/hwmon/pmbus/adm1266.c @@ -431,6 +431,69 @@ static const struct file_operations adm1266_clear_blac= kbox_fops =3D { .llseek =3D noop_llseek, }; =20 +/* + * SET_RTC (0xDF) is a 6-byte block (datasheet Rev. D, Table 84): + * bytes [1:0] - fractional seconds (1/65536 s, written as zero) + * bytes [5:2] - seconds since 1970-01-01 UTC, little-endian + * + * The driver seeds it once at probe via adm1266_rtc_set(). Over a + * long uptime the chip's counter drifts away from host wall-clock, + * so expose it via debugfs: + * + * read -- returns the chip's current seconds counter, which lets + * userspace observe host-vs-chip drift. + * write -- the kernel re-reads ktime_get_real_seconds() and writes + * it to SET_RTC. The write payload is ignored; userspace + * does not get to supply its own timestamp value, so + * there is no way to push a wrong time into the chip. + * + * A small userspace agent (chrony hook, systemd-timesyncd script, + * or a periodic cron job) can write to this file to keep the + * timestamp embedded in each blackbox record aligned with + * wall-clock across long uptimes. + */ +static int adm1266_rtc_get(void *data, u64 *val) +{ + struct i2c_client *client =3D data; + u8 buf[I2C_SMBUS_BLOCK_MAX]; + u32 seconds =3D 0; + int ret, i; + + guard(pmbus_lock)(client); + ret =3D i2c_smbus_read_block_data(client, ADM1266_SET_RTC, buf); + if (ret < 0) + return ret; + if (ret < 6) + return -EIO; + + for (i =3D 0; i < 4; i++) + seconds |=3D (u32)buf[2 + i] << (i * 8); + + *val =3D seconds; + + return 0; +} + +static int adm1266_rtc_set(void *data, u64 val) +{ + struct i2c_client *client =3D data; + time64_t kt =3D ktime_get_real_seconds(); + u8 write_buf[6] =3D { 0 }; + int i; + + /* User-supplied @val is ignored on purpose; the kernel owns the + * time source so userspace cannot push a wrong value into the chip. + */ + for (i =3D 0; i < 4; i++) + write_buf[2 + i] =3D (kt >> (i * 8)) & 0xFF; + + guard(pmbus_lock)(client); + return i2c_smbus_write_block_data(client, ADM1266_SET_RTC, + sizeof(write_buf), write_buf); +} +DEFINE_DEBUGFS_ATTRIBUTE(adm1266_rtc_fops, + adm1266_rtc_get, adm1266_rtc_set, "%llu\n"); + static void adm1266_init_debugfs(struct adm1266_data *data) { struct dentry *root; @@ -449,6 +512,8 @@ static void adm1266_init_debugfs(struct adm1266_data *d= ata) adm1266_powerup_counter_read); debugfs_create_file("clear_blackbox", 0200, data->debugfs_dir, data->clie= nt, &adm1266_clear_blackbox_fops); + debugfs_create_file("rtc", 0600, data->debugfs_dir, data->client, + &adm1266_rtc_fops); } =20 static int adm1266_nvmem_read_blackbox(struct adm1266_data *data, u8 *read= _buff) @@ -538,23 +603,6 @@ static int adm1266_config_nvmem(struct adm1266_data *d= ata) return 0; } =20 -static int adm1266_set_rtc(struct adm1266_data *data) -{ - time64_t kt; - char write_buf[6]; - int i; - - kt =3D ktime_get_real_seconds(); - - memset(write_buf, 0, sizeof(write_buf)); - - for (i =3D 0; i < 4; i++) - write_buf[2 + i] =3D (kt >> (i * 8)) & 0xFF; - - return i2c_smbus_write_block_data(data->client, ADM1266_SET_RTC, sizeof(w= rite_buf), - write_buf); -} - static int adm1266_probe(struct i2c_client *client) { struct adm1266_data *data; @@ -574,14 +622,14 @@ static int adm1266_probe(struct i2c_client *client) crc8_populate_msb(pmbus_crc_table, 0x7); mutex_init(&data->buf_mutex); =20 - ret =3D adm1266_set_rtc(data); - if (ret < 0) - return ret; - ret =3D pmbus_do_probe(client, &data->info); if (ret) return ret; =20 + ret =3D adm1266_rtc_set(client, 0); + if (ret < 0) + return ret; + ret =3D adm1266_config_nvmem(data); if (ret < 0) return ret; --=20 2.53.0