Lines Matching +full:reg +full:- +full:names
1 // SPDX-License-Identifier: GPL-2.0-or-later
10 * Copyright (c) 2013 Guenter Roeck <linux@roeck-us.net>
28 #include <linux/hwmon-sysfs.h>
80 { 0, 0, 0 }, /* temp - unused */
156 static int tmp401_register_to_temp(u16 reg, u8 config) in tmp401_register_to_temp() argument
158 int temp = reg; in tmp401_register_to_temp()
161 temp -= 64 * 256; in tmp401_register_to_temp()
169 temp = clamp_val(temp, -64000, 191000); in tmp401_temp_to_register()
174 return DIV_ROUND_CLOSEST(temp * (1 << (8 - zbits)), 1000) << zbits; in tmp401_temp_to_register()
181 int num_regs = data->kind == tmp411 ? 6 : 4; in tmp401_update_device_reg16()
182 int num_sensors = data->kind == tmp432 ? 3 : 2; in tmp401_update_device_reg16()
188 regaddr = data->kind == tmp432 ? in tmp401_update_device_reg16()
200 data->temp[j][i] = j == 3 ? val << 8 : val; in tmp401_update_device_reg16()
209 struct i2c_client *client = data->client; in tmp401_update_device()
214 mutex_lock(&data->update_lock); in tmp401_update_device()
216 next_update = data->last_updated + in tmp401_update_device()
217 msecs_to_jiffies(data->update_interval); in tmp401_update_device()
218 if (time_after(jiffies, next_update) || !data->valid) { in tmp401_update_device()
219 if (data->kind != tmp432) { in tmp401_update_device()
229 data->status[0] = in tmp401_update_device()
231 data->status[1] = in tmp401_update_device()
234 data->status[2] = in tmp401_update_device()
237 data->status[3] = val & (TMP401_STATUS_LOCAL_CRIT in tmp401_update_device()
240 for (i = 0; i < ARRAY_SIZE(data->status); i++) { in tmp401_update_device()
247 data->status[i] = val; in tmp401_update_device()
256 data->config = val; in tmp401_update_device()
267 data->temp_crit_hyst = val; in tmp401_update_device()
269 data->last_updated = jiffies; in tmp401_update_device()
270 data->valid = 1; in tmp401_update_device()
274 mutex_unlock(&data->update_lock); in tmp401_update_device()
281 int nr = to_sensor_dev_attr_2(devattr)->nr; in temp_show()
282 int index = to_sensor_dev_attr_2(devattr)->index; in temp_show()
289 tmp401_register_to_temp(data->temp[nr][index], data->config)); in temp_show()
296 int temp, index = to_sensor_dev_attr(devattr)->index; in temp_crit_hyst_show()
302 mutex_lock(&data->update_lock); in temp_crit_hyst_show()
303 temp = tmp401_register_to_temp(data->temp[3][index], data->config); in temp_crit_hyst_show()
304 temp -= data->temp_crit_hyst * 1000; in temp_crit_hyst_show()
305 mutex_unlock(&data->update_lock); in temp_crit_hyst_show()
313 int nr = to_sensor_dev_attr_2(devattr)->nr; in status_show()
314 int mask = to_sensor_dev_attr_2(devattr)->index; in status_show()
320 return sprintf(buf, "%d\n", !!(data->status[nr] & mask)); in status_show()
327 int nr = to_sensor_dev_attr_2(devattr)->nr; in temp_store()
328 int index = to_sensor_dev_attr_2(devattr)->index; in temp_store()
330 struct i2c_client *client = data->client; in temp_store()
332 u16 reg; in temp_store() local
336 return -EINVAL; in temp_store()
338 reg = tmp401_temp_to_register(val, data->config, nr == 3 ? 8 : 4); in temp_store()
340 mutex_lock(&data->update_lock); in temp_store()
342 regaddr = data->kind == tmp432 ? TMP432_TEMP_MSB_WRITE[nr][index] in temp_store()
345 i2c_smbus_write_byte_data(client, regaddr, reg >> 8); in temp_store()
347 /* Hardware expects big endian data --> use _swapped */ in temp_store()
348 i2c_smbus_write_word_swapped(client, regaddr, reg); in temp_store()
350 data->temp[nr][index] = reg; in temp_store()
352 mutex_unlock(&data->update_lock); in temp_store()
361 int temp, index = to_sensor_dev_attr(devattr)->index; in temp_crit_hyst_store()
364 u8 reg; in temp_crit_hyst_store() local
370 return -EINVAL; in temp_crit_hyst_store()
372 if (data->config & TMP401_CONFIG_RANGE) in temp_crit_hyst_store()
373 val = clamp_val(val, -64000, 191000); in temp_crit_hyst_store()
377 mutex_lock(&data->update_lock); in temp_crit_hyst_store()
378 temp = tmp401_register_to_temp(data->temp[3][index], data->config); in temp_crit_hyst_store()
379 val = clamp_val(val, temp - 255000, temp); in temp_crit_hyst_store()
380 reg = ((temp - val) + 500) / 1000; in temp_crit_hyst_store()
382 i2c_smbus_write_byte_data(data->client, TMP401_TEMP_CRIT_HYST, in temp_crit_hyst_store()
383 reg); in temp_crit_hyst_store()
385 data->temp_crit_hyst = reg; in temp_crit_hyst_store()
387 mutex_unlock(&data->update_lock); in temp_crit_hyst_store()
395 * (0x30-0x37).
402 struct i2c_client *client = data->client; in reset_temp_history_store()
406 return -EINVAL; in reset_temp_history_store()
412 return -EINVAL; in reset_temp_history_store()
414 mutex_lock(&data->update_lock); in reset_temp_history_store()
416 data->valid = 0; in reset_temp_history_store()
417 mutex_unlock(&data->update_lock); in reset_temp_history_store()
427 return sprintf(buf, "%u\n", data->update_interval); in update_interval_show()
435 struct i2c_client *client = data->client; in update_interval_store()
445 * interval = (1 << (7 - rate)) * 125; in update_interval_store()
447 * rate = 7 - __fls(interval * 4 / (125 * 3)); in update_interval_store()
452 rate = 7 - __fls(val * 4 / (125 * 3)); in update_interval_store()
453 mutex_lock(&data->update_lock); in update_interval_store()
455 data->update_interval = (1 << (7 - rate)) * 125; in update_interval_store()
456 mutex_unlock(&data->update_lock); in update_interval_store()
519 * temperature measured since power-on, chip-reset, or
599 data->update_interval = 500; in tmp401_init_client()
621 struct i2c_adapter *adapter = client->adapter; in tmp401_detect()
622 u8 reg; in tmp401_detect() local
625 return -ENODEV; in tmp401_detect()
628 reg = i2c_smbus_read_byte_data(client, TMP401_MANUFACTURER_ID_REG); in tmp401_detect()
629 if (reg != TMP401_MANUFACTURER_ID) in tmp401_detect()
630 return -ENODEV; in tmp401_detect()
632 reg = i2c_smbus_read_byte_data(client, TMP401_DEVICE_ID_REG); in tmp401_detect()
634 switch (reg) { in tmp401_detect()
636 if (client->addr != 0x4c) in tmp401_detect()
637 return -ENODEV; in tmp401_detect()
641 if (client->addr != 0x4c) in tmp401_detect()
642 return -ENODEV; in tmp401_detect()
646 if (client->addr != 0x4d) in tmp401_detect()
647 return -ENODEV; in tmp401_detect()
651 if (client->addr != 0x4e) in tmp401_detect()
652 return -ENODEV; in tmp401_detect()
656 if (client->addr != 0x4c && client->addr != 0x4d) in tmp401_detect()
657 return -ENODEV; in tmp401_detect()
661 if (client->addr != 0x4c && client->addr != 0x4d) in tmp401_detect()
662 return -ENODEV; in tmp401_detect()
669 return -ENODEV; in tmp401_detect()
672 reg = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ); in tmp401_detect()
673 if (reg & 0x1b) in tmp401_detect()
674 return -ENODEV; in tmp401_detect()
676 reg = i2c_smbus_read_byte_data(client, TMP401_CONVERSION_RATE_READ); in tmp401_detect()
677 /* Datasheet says: 0x1-0x6 */ in tmp401_detect()
678 if (reg > 15) in tmp401_detect()
679 return -ENODEV; in tmp401_detect()
681 strlcpy(info->type, tmp401_id[kind].name, I2C_NAME_SIZE); in tmp401_detect()
688 static const char * const names[] = { in tmp401_probe() local
691 struct device *dev = &client->dev; in tmp401_probe()
698 return -ENOMEM; in tmp401_probe()
700 data->client = client; in tmp401_probe()
701 mutex_init(&data->update_lock); in tmp401_probe()
702 data->kind = i2c_match_id(tmp401_id, client)->driver_data; in tmp401_probe()
710 data->groups[groups++] = &tmp401_group; in tmp401_probe()
713 if (data->kind == tmp411) in tmp401_probe()
714 data->groups[groups++] = &tmp411_group; in tmp401_probe()
717 if (data->kind == tmp432) in tmp401_probe()
718 data->groups[groups++] = &tmp432_group; in tmp401_probe()
720 if (data->kind == tmp461) in tmp401_probe()
721 data->groups[groups++] = &tmp461_group; in tmp401_probe()
723 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in tmp401_probe()
724 data, data->groups); in tmp401_probe()
728 dev_info(dev, "Detected TI %s chip\n", names[data->kind]); in tmp401_probe()