mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-09-21 20:22:13 +08:00
hwmon: (tmp421) introduce a channel struct
This is a preparatory change. Upcoming patches will introduce more per-channel parameters so it's worth organizing them into a struct. Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com> Link: https://lore.kernel.org/r/baf34d95983a6b58a3e39e4c098e5979e541572e.1634029538.git.krzysztof.adamski@nokia.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
beee7890c3
commit
5e3dbeac37
@ -87,6 +87,10 @@ static const struct of_device_id __maybe_unused tmp421_of_match[] = {
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, tmp421_of_match);
|
||||
|
||||
struct tmp421_channel {
|
||||
s16 temp;
|
||||
};
|
||||
|
||||
struct tmp421_data {
|
||||
struct i2c_client *client;
|
||||
struct mutex update_lock;
|
||||
@ -98,7 +102,7 @@ struct tmp421_data {
|
||||
unsigned long last_updated;
|
||||
unsigned long channels;
|
||||
u8 config;
|
||||
s16 temp[MAX_CHANNELS];
|
||||
struct tmp421_channel channel[MAX_CHANNELS];
|
||||
};
|
||||
|
||||
static int temp_from_raw(u16 reg, bool extended)
|
||||
@ -133,12 +137,12 @@ static int tmp421_update_device(struct tmp421_data *data)
|
||||
ret = i2c_smbus_read_byte_data(client, TMP421_TEMP_MSB[i]);
|
||||
if (ret < 0)
|
||||
goto exit;
|
||||
data->temp[i] = ret << 8;
|
||||
data->channel[i].temp = ret << 8;
|
||||
|
||||
ret = i2c_smbus_read_byte_data(client, TMP421_TEMP_LSB[i]);
|
||||
if (ret < 0)
|
||||
goto exit;
|
||||
data->temp[i] |= ret;
|
||||
data->channel[i].temp |= ret;
|
||||
}
|
||||
data->last_updated = jiffies;
|
||||
data->valid = true;
|
||||
@ -167,7 +171,7 @@ static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
|
||||
|
||||
switch (attr) {
|
||||
case hwmon_temp_input:
|
||||
*val = temp_from_raw(tmp421->temp[channel],
|
||||
*val = temp_from_raw(tmp421->channel[channel].temp,
|
||||
tmp421->config & TMP421_CONFIG_RANGE);
|
||||
return 0;
|
||||
case hwmon_temp_fault:
|
||||
@ -175,7 +179,7 @@ static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
|
||||
* Any of OPEN or /PVLD bits indicate a hardware mulfunction
|
||||
* and the conversion result may be incorrect
|
||||
*/
|
||||
*val = !!(tmp421->temp[channel] & 0x03);
|
||||
*val = !!(tmp421->channel[channel].temp & 0x03);
|
||||
return 0;
|
||||
default:
|
||||
return -EOPNOTSUPP;
|
||||
|
Loading…
Reference in New Issue
Block a user