mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 09:20:13 -04:00
misc: amd-sbi: Consolidate Common SBTSI Probe Path
Refactor shared probe procedures into sbtsi_probe_common() to ensure that I2C and I3C probes focus solely on bus-specific allocation and device configuration. The utility function reads the configuration register via sbtsi_xfer(), initializes ext_range_mode and read_order, assigns the driver data, and registers the hwmon auxiliary device. Routing register access through sbtsi_xfer() keeps the probe path bus-agnostic, so no transfer logic has to be duplicated when SB-TSI over I3C support is added in a later patch. Reviewed-by: Akshay Gupta <Akshay.Gupta@amd.com> Signed-off-by: Prathima <Prathima.Lk@amd.com> Link: https://patch.msgid.link/20260710111642.850022-5-Akshay.Gupta@amd.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
d4f8babf8e
commit
ba27ea7abd
@@ -79,31 +79,41 @@ static int sbtsi_create_hwmon_adev(struct device *dev, u8 dev_addr)
|
||||
return devm_add_action_or_reset(dev, sbtsi_unregister_hwmon_adev, adev);
|
||||
}
|
||||
|
||||
static int sbtsi_probe_common(struct device *dev, struct sbtsi_data *data)
|
||||
{
|
||||
u8 val;
|
||||
int err;
|
||||
|
||||
err = sbtsi_xfer(data, SBTSI_REG_CONFIG, &val, true);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
data->ext_range_mode = FIELD_GET(BIT(SBTSI_CONFIG_EXT_RANGE_SHIFT), val);
|
||||
data->read_order = FIELD_GET(BIT(SBTSI_CONFIG_READ_ORDER_SHIFT), val);
|
||||
|
||||
dev_set_drvdata(dev, data);
|
||||
return sbtsi_create_hwmon_adev(dev, data->dev_addr);
|
||||
}
|
||||
|
||||
static int sbtsi_i2c_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);
|
||||
/* In a multi-socket system, devices that are otherwise identical do not
|
||||
* share the same static address; each instance resides at a unique I2C
|
||||
* client address on the same or different bus. Use the I2C client
|
||||
* address as the auxiliary device instance ID to ensure each socket
|
||||
* receives a distinct auxiliary device name.
|
||||
*/
|
||||
return sbtsi_create_hwmon_adev(dev, client->addr);
|
||||
data->dev_addr = client->addr;
|
||||
return sbtsi_probe_common(dev, data);
|
||||
}
|
||||
|
||||
static const struct i2c_device_id sbtsi_id[] = {
|
||||
|
||||
@@ -14,11 +14,13 @@
|
||||
/**
|
||||
* struct sbtsi_data - driver private data for an AMD SB-TSI device
|
||||
* @client: underlying I2C client
|
||||
* @dev_addr: I2C device address, used as the auxiliary device instance id
|
||||
* @ext_range_mode: sensor uses extended temperature range
|
||||
* @read_order: if set, decimal part must be read before integer part
|
||||
*/
|
||||
struct sbtsi_data {
|
||||
struct i2c_client *client;
|
||||
u8 dev_addr;
|
||||
bool ext_range_mode;
|
||||
bool read_order;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user