hwmon/misc: amd-sbi: Move sbtsi register transfer to core abstraction

Move the I2C read/write byte operations from the sbtsi hwmon driver into
a common sbtsi_xfer() function in tsi-core.c.
This decouples the hwmon sensor driver from the underlying bus transport,
preparing for I3C support in a subsequent patch.
This patch does not introduce any functional changes. The updates are
limited to code organization/cleanup and should not affect the runtime
behavior of the driver

Reviewed-by: Akshay Gupta <Akshay.Gupta@amd.com>
Signed-off-by: Prathima <Prathima.Lk@amd.com>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Link: https://patch.msgid.link/20260710111642.850022-4-Akshay.Gupta@amd.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Prathima
2026-07-10 16:46:37 +05:30
committed by Greg Kroah-Hartman
parent 54a7848c24
commit d4f8babf8e
4 changed files with 50 additions and 12 deletions

View File

@@ -70,15 +70,10 @@ static int sbtsi_temp_read(struct sbtsi_data *data, u8 reg1, u8 reg2,
{
int ret;
ret = i2c_smbus_read_byte_data(data->client, reg1);
if (ret < 0)
return ret;
*val1 = ret;
ret = i2c_smbus_read_byte_data(data->client, reg2);
if (ret < 0)
return ret;
*val2 = ret;
return 0;
ret = sbtsi_xfer(data, reg1, val1, true);
if (!ret)
ret = sbtsi_xfer(data, reg2, val2, true);
return ret;
}
/*
@@ -89,9 +84,9 @@ static int sbtsi_temp_write(struct sbtsi_data *data, u8 reg_int, u8 reg_dec,
{
int ret;
ret = i2c_smbus_write_byte_data(data->client, reg_int, val_int);
ret = sbtsi_xfer(data, reg_int, &val_int, false);
if (!ret)
ret = i2c_smbus_write_byte_data(data->client, reg_dec, val_dec);
ret = sbtsi_xfer(data, reg_dec, &val_dec, false);
return ret;
}

View File

@@ -3,5 +3,5 @@ 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-objs += tsi.o tsi-core.o
obj-$(CONFIG_AMD_SBTSI) += sbtsi.o

View File

@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* tsi-core.c - file defining SB-TSI protocols compliant
* AMD SoC device.
*
* Copyright (C) 2026 Advanced Micro Devices, Inc.
*/
#include <linux/module.h>
#include <linux/misc/tsi.h>
/* I2C transfer function */
static int sbtsi_i2c_xfer(struct sbtsi_data *data, u8 reg, u8 *val, bool is_read)
{
if (is_read) {
int ret = i2c_smbus_read_byte_data(data->client, reg);
if (ret < 0)
return ret;
*val = ret;
return 0;
}
return i2c_smbus_write_byte_data(data->client, reg, *val);
}
int sbtsi_xfer(struct sbtsi_data *data, u8 reg, u8 *val, bool is_read)
{
return sbtsi_i2c_xfer(data, reg, val, is_read);
}
EXPORT_SYMBOL_GPL(sbtsi_xfer);

View File

@@ -31,4 +31,17 @@ struct sbtsi_data {
#define AMD_SBTSI_ADEV "amd-sbtsi"
#define AMD_SBTSI_AUX_HWMON "temp-sensor"
/**
* sbtsi_xfer - Perform a register read or write transfer on an AMD SB-TSI device.
*
* @data: Pointer to the sbtsi_data structure containing the device context
* @reg: Register address to access.
* @val: Pointer to the value to read into or write from.
* @is_read: If true, performs a read transfer and stores the result in @val.
* If false, performs a write transfer using the value in @val.
*
* Returns 0 on success, or a negative error code on failure.
*/
int sbtsi_xfer(struct sbtsi_data *data, u8 reg, u8 *val, bool is_read);
#endif /* _LINUX_MISC_TSI_H_ */