/* Hysteresis register holds a relative value, while we want to present an absolute to user-space */ static ssize_t show_temp2_crit_hyst(struct device *dev, struct device_attribute *dummy, char *buf) { struct lm63_data *data = lm63_update_device(dev); return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[2]) - TEMP8_FROM_REG(data->temp2_crit_hyst)); }
static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct lm63_data *data = lm63_update_device(dev); return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index])); }
/* * Hysteresis register holds a relative value, while we want to present * an absolute to user-space */ static ssize_t temp2_crit_hyst_show(struct device *dev, struct device_attribute *dummy, char *buf) { struct lm63_data *data = lm63_update_device(dev); return sprintf(buf, "%d\n", temp8_from_reg(data, 2) + data->temp2_offset - TEMP8_FROM_REG(data->temp2_crit_hyst)); }
static ssize_t show_lut_temp_hyst(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct lm63_data *data = lm63_update_device(dev); return sprintf(buf, "%d\n", lut_temp_from_reg(data, attr->index) + data->temp2_offset - TEMP8_FROM_REG(data->lut_temp_hyst)); }
/* And now the other way around, user-space provides an absolute hysteresis value and we have to store a relative one */ static ssize_t set_temp2_crit_hyst(struct device *dev, struct device_attribute *dummy, const char *buf, size_t count) { struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = i2c_get_clientdata(client); long val = simple_strtol(buf, NULL, 10); long hyst; mutex_lock(&data->update_lock); hyst = TEMP8_FROM_REG(data->temp8[2]) - val; i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, HYST_TO_REG(hyst)); mutex_unlock(&data->update_lock); return count; }
static inline int temp8_from_reg(struct lm63_data *data, int nr) { if (data->remote_unsigned) return TEMP8_FROM_REG((u8)data->temp8[nr]); return TEMP8_FROM_REG(data->temp8[nr]); }