hwmon: (tmp421) introduce a channel struct
authorKrzysztof Adamski <krzysztof.adamski@nokia.com>
Tue, 12 Oct 2021 09:26:55 +0000 (11:26 +0200)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 12 Oct 2021 14:25:34 +0000 (07:25 -0700)
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>
drivers/hwmon/tmp421.c

index 356c96c3588bd8d8fea053102b23abeef76bc772..707310d616a45c5a7a7d028206ec79bbd226adf4 100644 (file)
@@ -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;