hwmon: (it87) Split temperature sensor detection to separate function
The temperature sensor type will need to be used in multiple places, so split it out into its own function. Signed-off-by: Frank Crawford <frank@crawford.emu.id.au> Link: https://lore.kernel.org/r/20230707123005.956415-2-frank@crawford.emu.id.au [groeck: Dropped unnecessary 'type' variable in show_temp_type()] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
49ffb5eefe
commit
4018e0a9c0
|
@ -1159,28 +1159,43 @@ static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, 0);
|
|||
static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, 0);
|
||||
static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, 0);
|
||||
|
||||
static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
static int get_temp_type(struct it87_data *data, int index)
|
||||
{
|
||||
struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
|
||||
int nr = sensor_attr->index;
|
||||
struct it87_data *data = it87_update_device(dev);
|
||||
/*
|
||||
* 2 is deprecated;
|
||||
* 3 = thermal diode;
|
||||
* 4 = thermistor;
|
||||
* 5 = AMDTSI;
|
||||
* 6 = Intel PECI;
|
||||
* 0 = disabled
|
||||
*/
|
||||
u8 reg, extra;
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
int type = 0;
|
||||
|
||||
reg = data->sensor; /* In case value is updated while used */
|
||||
extra = data->extra;
|
||||
|
||||
if ((has_temp_peci(data, nr) && (reg >> 6 == nr + 1)) ||
|
||||
(has_temp_old_peci(data, nr) && (extra & 0x80)))
|
||||
return sprintf(buf, "6\n"); /* Intel PECI */
|
||||
if (reg & (1 << nr))
|
||||
return sprintf(buf, "3\n"); /* thermal diode */
|
||||
if (reg & (8 << nr))
|
||||
return sprintf(buf, "4\n"); /* thermistor */
|
||||
return sprintf(buf, "0\n"); /* disabled */
|
||||
if ((has_temp_peci(data, index) && (reg >> 6 == index + 1)) ||
|
||||
(has_temp_old_peci(data, index) && (extra & 0x80)))
|
||||
type = 6; /* Intel PECI */
|
||||
else if (reg & BIT(index))
|
||||
type = 3; /* thermal diode */
|
||||
else if (reg & BIT(index + 3))
|
||||
type = 4; /* thermistor */
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
|
||||
struct it87_data *data = it87_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", get_temp_type(data, sensor_attr->index));
|
||||
}
|
||||
|
||||
static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
|
||||
|
|
Loading…
Reference in New Issue