static inline int temp_from_u16_adt7461(struct lm90_data *data, u16 val) { if (data->flags & LM90_FLAG_ADT7461_EXT) return (val - 0x4000) / 64 * 250; else return temp_from_s16(val); }
static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct lm90_data *data = lm90_update_device(dev); int temp; if (data->kind == adt7461) temp = temp_from_u16_adt7461(data, data->temp11[attr->index]); else if (data->kind == max6646) temp = temp_from_u16(data->temp11[attr->index]); else temp = temp_from_s16(data->temp11[attr->index]); return sprintf(buf, "%d\n", temp); }
static ssize_t show_temp_value(struct device *dev, struct device_attribute *devattr, char *buf) { int index = to_sensor_dev_attr(devattr)->index; struct tmp421_data *data = tmp421_update_device(dev); int temp; mutex_lock(&data->update_lock); if (data->config & TMP421_CONFIG_RANGE) temp = temp_from_u16(data->temp[index]); else temp = temp_from_s16(data->temp[index]); mutex_unlock(&data->update_lock); return sprintf(buf, "%d\n", temp); }
static int tmp421_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { struct tmp421_data *tmp421 = tmp421_update_device(dev); switch (attr) { case hwmon_temp_input: if (tmp421->config & TMP421_CONFIG_RANGE) *val = temp_from_u16(tmp421->temp[channel]); else *val = temp_from_s16(tmp421->temp[channel]); return 0; case hwmon_temp_fault: /* * The OPEN bit signals a fault. This is bit 0 of the temperature * register (low byte). */ *val = tmp421->temp[channel] & 0x01; return 0; default: return -EOPNOTSUPP; } }