Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mlxbf-bootctl: Support sysfs entries for RTC battery status

This patch extends the mlxbf-bootctl driver's sysfs entries
to support read access for the board's RTC battery status.
A successful read from this attribute returns the status of
the board's RTC battery. The RTC battery status register is
also cleared upon successful read operation.

Signed-off-by: Xiangrong Li <xiangrongl@nvidia.com>
Reviewed-by: David Thompson <davthompson@nvidia.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20250124144655.48564-1-xiangrongl@nvidia.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

authored by

Xiangrong Li and committed by
Ilpo Järvinen
5d40a857 2014c95a

+35
+10
Documentation/ABI/testing/sysfs-platform-mellanox-bootctl
··· 150 150 The "mfg_lock" sysfs attribute is write-only. 151 151 A successful write to this attribute will latch the 152 152 board-level attributes into EEPROM, making them read-only. 153 + 154 + What: /sys/bus/platform/devices/MLNXBF04:00/rtc_battery 155 + Date: June 2025 156 + KernelVersion: 6.15 157 + Contact: "Xiangrong Li <xiangrongl@nvidia.com>" 158 + Description: 159 + The "rtc_battery" sysfs attribute is read-only. 160 + A successful read from this attribute returns the status of 161 + the board's RTC battery. The RTC battery status register is 162 + also cleared upon successful read operation.
+20
drivers/platform/mellanox/mlxbf-bootctl.c
··· 91 91 static DEFINE_MUTEX(icm_ops_lock); 92 92 static DEFINE_MUTEX(os_up_lock); 93 93 static DEFINE_MUTEX(mfg_ops_lock); 94 + static DEFINE_MUTEX(rtc_ops_lock); 94 95 95 96 /* 96 97 * Objects are stored within the MFG partition per type. ··· 488 487 mutex_unlock(&icm_ops_lock); 489 488 490 489 return res.a0 ? -EPERM : count; 490 + } 491 + 492 + static ssize_t rtc_battery_show(struct device *dev, 493 + struct device_attribute *attr, 494 + char *buf) 495 + { 496 + struct arm_smccc_res res; 497 + 498 + mutex_lock(&rtc_ops_lock); 499 + arm_smccc_smc(MLNX_HANDLE_GET_RTC_LOW_BATT, 0, 0, 0, 0, 500 + 0, 0, 0, &res); 501 + mutex_unlock(&rtc_ops_lock); 502 + 503 + if (res.a0) 504 + return -EPERM; 505 + 506 + return sysfs_emit(buf, "0x%lx\n", res.a1); 491 507 } 492 508 493 509 static ssize_t os_up_store(struct device *dev, ··· 924 906 static DEVICE_ATTR_RW(uuid); 925 907 static DEVICE_ATTR_RW(rev); 926 908 static DEVICE_ATTR_WO(mfg_lock); 909 + static DEVICE_ATTR_RO(rtc_battery); 927 910 928 911 static struct attribute *mlxbf_bootctl_attrs[] = { 929 912 &dev_attr_post_reset_wdog.attr, ··· 944 925 &dev_attr_uuid.attr, 945 926 &dev_attr_rev.attr, 946 927 &dev_attr_mfg_lock.attr, 928 + &dev_attr_rtc_battery.attr, 947 929 NULL 948 930 }; 949 931
+5
drivers/platform/mellanox/mlxbf-bootctl.h
··· 103 103 */ 104 104 #define MLNX_HANDLE_OS_UP 0x82000014 105 105 106 + /* 107 + * SMC function ID to get and clear the RTC low voltage bit 108 + */ 109 + #define MLNX_HANDLE_GET_RTC_LOW_BATT 0x82000023 110 + 106 111 /* SMC function IDs for SiP Service queries */ 107 112 #define MLXBF_BOOTCTL_SIP_SVC_CALL_COUNT 0x8200ff00 108 113 #define MLXBF_BOOTCTL_SIP_SVC_UID 0x8200ff01