[PATCH v1 3/6] misc: amd-sbi: Split SBTSI hwmon sensor handling into a separate entity

Akshay Gupta
2026-03-23T11:09:05Z

From: Prathima <Prathima.Lk@amd.com>

Separate SBTSI hwmon sensor handling from the core path to improve
code organization and maintainability.

This keeps core transport/register access independent while preserving
existing hwmon functionality through a dedicated hwmon component.

Reviewed-by: Akshay Gupta <Akshay.Gupta@amd.com>
Signed-off-by: Prathima <Prathima.Lk@amd.com>
---
drivers/misc/amd-sbi/Kconfig | 12 +-
drivers/misc/amd-sbi/Makefile | 2 +
drivers/misc/amd-sbi/tsi-core.h | 30 +++++
drivers/misc/amd-sbi/{sbtsi.c => tsi-hwmon.c} | 120 ++++--------------
drivers/misc/amd-sbi/tsi.c | 77 +++++++++++
5 files changed, 142 insertions(+), 99 deletions(-)
create mode 100644 drivers/misc/amd-sbi/tsi-core.h
rename drivers/misc/amd-sbi/{sbtsi.c => tsi-hwmon.c} (57%)
create mode 100644 drivers/misc/amd-sbi/tsi.c

diff --git a/drivers/misc/amd-sbi/Kconfig b/drivers/misc/amd-sbi/Kconfig
index 19a8d596e8f5..2710860a86c7 100644
--- a/drivers/misc/amd-sbi/Kconfig
+++ b/drivers/misc/amd-sbi/Kconfig
@@ -25,7 +25,6 @@ config SENSORS_SBTSI
tristate "Emulated SB-TSI temperature sensor"
depends on I2C
depends on ARM || ARM64 || COMPILE_TEST
- depends on HWMON
help
If you say yes here you get support for emulated temperature
sensors on AMD SoCs with SB-TSI interface connected to a BMC device.
@@ -33,3 +32,14 @@ config SENSORS_SBTSI

This driver can also be built as a module. If so, the module will
be called sbtsi.
+
+config AMD_SBTSI_HWMON
+ bool "SBTSI hardware monitoring for AMD platforms"
+ depends on SENSORS_SBTSI && HWMON
+ depends on !(SENSORS_SBTSI=y && HWMON=m)
+ default y
+ help
+ This provides support for TSI device hardware monitoring.
+ When enabled, a hwmon device is created for each socket to expose
+ temperature monitoring data through the standard Linux
+ hwmon interface.
diff --git a/drivers/misc/amd-sbi/Makefile b/drivers/misc/amd-sbi/Makefile
index f04273c0d3ad..a874136e438f 100644
--- a/drivers/misc/amd-sbi/Makefile
+++ b/drivers/misc/amd-sbi/Makefile
@@ -3,4 +3,6 @@ sbrmi-i2c-objs += rmi-i2c.o rmi-core.o
sbrmi-i2c-$(CONFIG_AMD_SBRMI_HWMON) += rmi-hwmon.o
obj-$(CONFIG_AMD_SBRMI_I2C) += sbrmi-i2c.o
# SBTSI Configuration
+sbtsi-objs += tsi.o
+sbtsi-$(CONFIG_AMD_SBTSI_HWMON) += tsi-hwmon.o
obj-$(CONFIG_SENSORS_SBTSI) += sbtsi.o
diff --git a/drivers/misc/amd-sbi/tsi-core.h b/drivers/misc/amd-sbi/tsi-core.h
new file mode 100644
index 000000000000..e60cf25fda7a
--- /dev/null
+++ b/drivers/misc/amd-sbi/tsi-core.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2026 Advanced Micro Devices, Inc.
+ */
+
+#ifndef _TSI_CORE_H_
+#define _TSI_CORE_H_
+
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/of.h>
+
+/* Each client has this additional data */
+struct sbtsi_data {
+ struct i2c_client *client;
+ bool ext_range_mode;
+ bool read_order;
+};
+
+#ifdef CONFIG_AMD_SBTSI_HWMON
+int create_sbtsi_hwmon_sensor_device(struct device *dev, struct sbtsi_data *data);
+#else
+static inline int create_sbtsi_hwmon_sensor_device(struct device *dev, struct sbtsi_data *data)
+{
+ return 0;
+}
+#endif
+#endif /*_TSI_CORE_H_*/
diff --git a/drivers/misc/amd-sbi/sbtsi.c b/drivers/misc/amd-sbi/tsi-hwmon.c
similarity index 57%
rename from drivers/misc/amd-sbi/sbtsi.c
rename to drivers/misc/amd-sbi/tsi-hwmon.c
index e09b10c17771..efd450a85d34 100644
--- a/drivers/misc/amd-sbi/sbtsi.c
+++ b/drivers/misc/amd-sbi/tsi-hwmon.c
@@ -1,59 +1,31 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * sbtsi.c - hwmon driver for a SBI Temperature Sensor Interface (SB-TSI)
- * compliant AMD SoC temperature device.
+ * tsi-hwmon.c - hwmon sensor support for side band TSI
*
* Copyright (c) 2020, Google Inc.
* Copyright (c) 2020, Kun Yi <kunyi@google.com>
*/

-#include <linux/err.h>
-#include <linux/i2c.h>
-#include <linux/init.h>
#include <linux/hwmon.h>
-#include <linux/module.h>
-#include <linux/of.h>
-#include <linux/bitfield.h>
+#include "tsi-core.h"

/*
* SB-TSI registers only support SMBus byte data access. "_INT" registers are
* the integer part of a temperature value or limit, and "_DEC" registers are
* corresponding decimal parts.
*/
-#define SBTSI_REG_TEMP_INT 0x01 /* RO */
-#define SBTSI_REG_STATUS 0x02 /* RO */
-#define SBTSI_REG_CONFIG 0x03 /* RO */
-#define SBTSI_REG_TEMP_HIGH_INT 0x07 /* RW */
-#define SBTSI_REG_TEMP_LOW_INT 0x08 /* RW */
-#define SBTSI_REG_TEMP_DEC 0x10 /* RW */
-#define SBTSI_REG_TEMP_HIGH_DEC 0x13 /* RW */
-#define SBTSI_REG_TEMP_LOW_DEC 0x14 /* RW */
+#define SBTSI_REG_TEMP_INT 0x01 /* RO */
+#define SBTSI_REG_STATUS 0x02 /* RO */
+#define SBTSI_REG_TEMP_HIGH_INT 0x07 /* RW */
+#define SBTSI_REG_TEMP_LOW_INT 0x08 /* RW */
+#define SBTSI_REG_TEMP_DEC 0x10 /* RW */
+#define SBTSI_REG_TEMP_HIGH_DEC 0x13 /* RW */
+#define SBTSI_REG_TEMP_LOW_DEC 0x14 /* RW */

-/*
- * Bit for reporting value with temperature measurement range.
- * bit == 0: Use default temperature range (0C to 255.875C).
- * bit == 1: Use extended temperature range (-49C to +206.875C).
- */
-#define SBTSI_CONFIG_EXT_RANGE_SHIFT 2
-/*
- * ReadOrder bit specifies the reading order of integer and decimal part of
- * CPU temperature for atomic reads. If bit == 0, reading integer part triggers
- * latching of the decimal part, so integer part should be read first.
- * If bit == 1, read order should be reversed.
- */
-#define SBTSI_CONFIG_READ_ORDER_SHIFT 5
-
-#define SBTSI_TEMP_EXT_RANGE_ADJ 49000
-
-#define SBTSI_TEMP_MIN 0
-#define SBTSI_TEMP_MAX 255875
+#define SBTSI_TEMP_EXT_RANGE_ADJ 49000

-/* Each client has this additional data */
-struct sbtsi_data {
- struct i2c_client *client;
- bool ext_range_mode;
- bool read_order;
-};
+#define SBTSI_TEMP_MIN 0
+#define SBTSI_TEMP_MAX 255875

/*
* From SB-TSI spec: CPU temperature readings and limit registers encode the
@@ -85,7 +57,7 @@ static inline void sbtsi_mc_to_reg(s32 temp, u8 *integer, u8 *decimal)
}

static int sbtsi_read(struct device *dev, enum hwmon_sensor_types type,
- u32 attr, int channel, long *val)
+ u32 attr, int channel, long *val)
{
struct sbtsi_data *data = dev_get_drvdata(dev);
s32 temp_int, temp_dec;
@@ -112,12 +84,6 @@ static int sbtsi_read(struct device *dev, enum hwmon_sensor_types type,
return -EINVAL;
}

-
- if (temp_int < 0)
- return temp_int;
- if (temp_dec < 0)
- return temp_dec;
-
*val = sbtsi_reg_to_mc(temp_int, temp_dec);
if (data->ext_range_mode)
*val -= SBTSI_TEMP_EXT_RANGE_ADJ;
@@ -126,7 +92,7 @@ static int sbtsi_read(struct device *dev, enum hwmon_sensor_types type,
}

static int sbtsi_write(struct device *dev, enum hwmon_sensor_types type,
- u32 attr, int channel, long val)
+ u32 attr, int channel, long val)
{
struct sbtsi_data *data = dev_get_drvdata(dev);
int reg_int, reg_dec, err;
@@ -154,12 +120,15 @@ static int sbtsi_write(struct device *dev, enum hwmon_sensor_types type,
if (err)
return err;

- return i2c_smbus_write_byte_data(data->client, reg_dec, temp_dec);
+ err = i2c_smbus_write_byte_data(data->client, reg_dec, temp_dec);
+ if (err)
+ return err;
+ return 0;
}

static umode_t sbtsi_is_visible(const void *data,
- enum hwmon_sensor_types type,
- u32 attr, int channel)
+ enum hwmon_sensor_types type,
+ u32 attr, int channel)
{
switch (type) {
case hwmon_temp:
@@ -195,56 +164,11 @@ static const struct hwmon_chip_info sbtsi_chip_info = {
.info = sbtsi_info,
};

-static int sbtsi_probe(struct i2c_client *client)
+int create_sbtsi_hwmon_sensor_device(struct device *dev, struct sbtsi_data *data)
{
- struct device *dev = &client->dev;
struct device *hwmon_dev;
- struct sbtsi_data *data;
- int err;

- data = devm_kzalloc(dev, sizeof(struct sbtsi_data), GFP_KERNEL);
- if (!data)
- return -ENOMEM;
-
- data->client = client;
-
- err = i2c_smbus_read_byte_data(data->client, SBTSI_REG_CONFIG);
- if (err < 0)
- return err;
- data->ext_range_mode = FIELD_GET(BIT(SBTSI_CONFIG_EXT_RANGE_SHIFT), err);
- data->read_order = FIELD_GET(BIT(SBTSI_CONFIG_READ_ORDER_SHIFT), err);
-
- hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data,
+ hwmon_dev = devm_hwmon_device_register_with_info(dev, "sbtsi", data,
&sbtsi_chip_info, NULL);
-
return PTR_ERR_OR_ZERO(hwmon_dev);
}
-
-static const struct i2c_device_id sbtsi_id[] = {
- {"sbtsi"},
- {}
-};
-MODULE_DEVICE_TABLE(i2c, sbtsi_id);
-
-static const struct of_device_id __maybe_unused sbtsi_of_match[] = {
- {
- .compatible = "amd,sbtsi",
- },
- { },
-};
-MODULE_DEVICE_TABLE(of, sbtsi_of_match);
-
-static struct i2c_driver sbtsi_driver = {
- .driver = {
- .name = "sbtsi",
- .of_match_table = of_match_ptr(sbtsi_of_match),
- },
- .probe = sbtsi_probe,
- .id_table = sbtsi_id,
-};
-
-module_i2c_driver(sbtsi_driver);
-
-MODULE_AUTHOR("Kun Yi <kunyi@google.com>");
-MODULE_DESCRIPTION("Hwmon driver for AMD SB-TSI emulated sensor");
-MODULE_LICENSE("GPL");
diff --git a/drivers/misc/amd-sbi/tsi.c b/drivers/misc/amd-sbi/tsi.c
new file mode 100644
index 000000000000..df754e60d84b
--- /dev/null
+++ b/drivers/misc/amd-sbi/tsi.c
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * tsi.c - Side band TSI over I2C support for AMD out of band management.
+ *
+ * Copyright (c) 2020-2026, Google Inc.
+ * Copyright (c) 2020-2026, Kun Yi <kunyi@google.com>
+ */
+
+#include <linux/bitfield.h>
+#include "tsi-core.h"
+
+#define SBTSI_REG_CONFIG 0x03 /* RO */
+
+/*
+ * Bit for reporting value with temperature measurement range.
+ * bit == 0: Use default temperature range (0C to 255.875C).
+ * bit == 1: Use extended temperature range (-49C to +206.875C).
+ */
+#define SBTSI_CONFIG_EXT_RANGE_SHIFT 2
+
+/*
+ * ReadOrder bit specifies the reading order of integer and decimal part of
+ * CPU temperature for atomic reads. If bit == 0, reading integer part triggers
+ * latching of the decimal part, so integer part should be read first.
+ */
+
+#define SBTSI_CONFIG_READ_ORDER_SHIFT 5
+
+static int sbtsi_probe(struct i2c_client *client)
+{
+ struct device *dev = &client->dev;
+ struct sbtsi_data *data;
+ int err;
+
+ data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ data->client = client;
+ err = i2c_smbus_read_byte_data(data->client, SBTSI_REG_CONFIG);
+ if (err < 0)
+ return err;
+ data->ext_range_mode = FIELD_GET(BIT(SBTSI_CONFIG_EXT_RANGE_SHIFT), err);
+ data->read_order = FIELD_GET(BIT(SBTSI_CONFIG_READ_ORDER_SHIFT), err);
+
+ dev_set_drvdata(dev, data);
+ return create_sbtsi_hwmon_sensor_device(dev, data);
+}
+
+static const struct i2c_device_id sbtsi_id[] = {
+ {"sbtsi"},
+ {}
+};
+MODULE_DEVICE_TABLE(i2c, sbtsi_id);
+
+static const struct of_device_id __maybe_unused sbtsi_of_match[] = {
+ {
+ .compatible = "amd,sbtsi",
+ },
+ { },
+};
+MODULE_DEVICE_TABLE(of, sbtsi_of_match);
+
+static struct i2c_driver sbtsi_driver = {
+ .driver = {
+ .name = "sbtsi",
+ .of_match_table = of_match_ptr(sbtsi_of_match),
+ },
+ .probe = sbtsi_probe,
+ .id_table = sbtsi_id,
+};
+
+module_i2c_driver(sbtsi_driver);
+
+MODULE_AUTHOR("Kun Yi <kunyi@google.com>");
+MODULE_DESCRIPTION("Hwmon driver for AMD SB-TSI emulated sensor");
+MODULE_LICENSE("GPL");
--
2.34.1