static ssize_t tmp102_set_temp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); struct tmp102 *tmp102 = dev_get_drvdata(dev); int reg = sda->index; long val; int err; if (kstrtol(buf, 10, &val) < 0) return -EINVAL; val = clamp_val(val, -256000, 255000); err = regmap_write(tmp102->regmap, reg, tmp102_mC_to_reg(val)); return err ? : count; }
static int tmp102_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long temp) { struct tmp102 *tmp102 = dev_get_drvdata(dev); int reg; switch (attr) { case hwmon_temp_max_hyst: reg = TMP102_TLOW_REG; break; case hwmon_temp_max: reg = TMP102_THIGH_REG; break; default: return -EOPNOTSUPP; } temp = clamp_val(temp, -256000, 255000); return regmap_write(tmp102->regmap, reg, tmp102_mC_to_reg(temp)); }
static ssize_t tmp102_set_temp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); struct i2c_client *client = to_i2c_client(dev); struct tmp102 *tmp102 = i2c_get_clientdata(client); long val; int status; if (kstrtol(buf, 10, &val) < 0) return -EINVAL; val = clamp_val(val, -256000, 255000); mutex_lock(&tmp102->lock); tmp102->temp[sda->index] = val; status = i2c_smbus_write_word_swapped(client, tmp102_reg[sda->index], tmp102_mC_to_reg(val)); mutex_unlock(&tmp102->lock); return status ? : count; }