Lines Matching +full:static +full:- +full:beta

1 // SPDX-License-Identifier: GPL-2.0-or-later
10 * Copyright (c) 2013 Guenter Roeck <linux@roeck-us.net>
32 static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4c, 0x4d,
50 static const u8 TMP401_TEMP_MSB[7][3] = {
60 static const u8 TMP432_STATUS_REG[] = {
93 static const struct i2c_device_id tmp401_id[] = {
126 static bool tmp401_regmap_is_volatile(struct device *dev, unsigned int reg) in tmp401_regmap_is_volatile()
143 static int tmp401_reg_read(void *context, unsigned int reg, unsigned int *val) in tmp401_reg_read()
146 struct i2c_client *client = data->client; in tmp401_reg_read()
171 case 0x19: /* critical limits, 8-bit registers */ in tmp401_reg_read()
181 if (data->kind == tmp432) { in tmp401_reg_read()
228 static int tmp401_reg_write(void *context, unsigned int reg, unsigned int val) in tmp401_reg_write()
231 struct i2c_client *client = data->client; in tmp401_reg_write()
243 case 0x19: /* critical limits, 8-bit registers */ in tmp401_reg_write()
256 static const struct regmap_config tmp401_regmap_config = {
267 static int tmp401_register_to_temp(u16 reg, bool extended) in tmp401_register_to_temp()
272 temp -= 64 * 256; in tmp401_register_to_temp()
277 static u16 tmp401_temp_to_register(long temp, bool extended, int zbits) in tmp401_temp_to_register()
280 temp = clamp_val(temp, -64000, 191000); in tmp401_temp_to_register()
286 return DIV_ROUND_CLOSEST(temp * (1 << (8 - zbits)), 1000) << zbits; in tmp401_temp_to_register()
291 static const u8 tmp401_temp_reg_index[] = {
300 static const u8 tmp401_status_reg_index[] = {
307 static int tmp401_temp_read(struct device *dev, u32 attr, int channel, long *val) in tmp401_temp_read()
310 struct regmap *regmap = data->regmap; in tmp401_temp_read()
325 *val = tmp401_register_to_temp(regval, data->extended_range); in tmp401_temp_read()
328 mutex_lock(&data->update_lock); in tmp401_temp_read()
333 *val = tmp401_register_to_temp(regval, data->extended_range); in tmp401_temp_read()
337 *val -= regval * 1000; in tmp401_temp_read()
339 mutex_unlock(&data->update_lock); in tmp401_temp_read()
354 return -EOPNOTSUPP; in tmp401_temp_read()
359 static int tmp401_temp_write(struct device *dev, u32 attr, int channel, in tmp401_temp_write()
363 struct regmap *regmap = data->regmap; in tmp401_temp_write()
367 mutex_lock(&data->update_lock); in tmp401_temp_write()
373 regval = tmp401_temp_to_register(val, data->extended_range, in tmp401_temp_write()
378 if (data->extended_range) in tmp401_temp_write()
379 val = clamp_val(val, -64000, 191000); in tmp401_temp_write()
387 temp = tmp401_register_to_temp(regval, data->extended_range); in tmp401_temp_write()
388 val = clamp_val(val, temp - 255000, temp); in tmp401_temp_write()
389 regval = ((temp - val) + 500) / 1000; in tmp401_temp_write()
393 ret = -EOPNOTSUPP; in tmp401_temp_write()
396 mutex_unlock(&data->update_lock); in tmp401_temp_write()
400 static int tmp401_chip_read(struct device *dev, u32 attr, int channel, long *val) in tmp401_chip_read()
408 ret = regmap_read(data->regmap, TMP401_CONVERSION_RATE, &regval); in tmp401_chip_read()
411 *val = (1 << (7 - regval)) * 125; in tmp401_chip_read()
417 return -EOPNOTSUPP; in tmp401_chip_read()
423 static int tmp401_set_convrate(struct regmap *regmap, long val) in tmp401_set_convrate()
429 * interval = (1 << (7 - rate)) * 125; in tmp401_set_convrate()
431 * rate = 7 - __fls(interval * 4 / (125 * 3)); in tmp401_set_convrate()
436 rate = 7 - __fls(val * 4 / (125 * 3)); in tmp401_set_convrate()
440 static int tmp401_chip_write(struct device *dev, u32 attr, int channel, long val) in tmp401_chip_write()
443 struct regmap *regmap = data->regmap; in tmp401_chip_write()
446 mutex_lock(&data->update_lock); in tmp401_chip_write()
453 err = -EINVAL; in tmp401_chip_write()
458 * minimum/maximum registers (0x30-0x37). in tmp401_chip_write()
463 err = -EOPNOTSUPP; in tmp401_chip_write()
466 mutex_unlock(&data->update_lock); in tmp401_chip_write()
471 static int tmp401_read(struct device *dev, enum hwmon_sensor_types type, in tmp401_read()
480 return -EOPNOTSUPP; in tmp401_read()
484 static int tmp401_write(struct device *dev, enum hwmon_sensor_types type, in tmp401_write()
493 return -EOPNOTSUPP; in tmp401_write()
497 static umode_t tmp401_is_visible(const void *data, enum hwmon_sensor_types type, in tmp401_is_visible()
535 static const struct hwmon_ops tmp401_ops = {
543 static int tmp401_init_client(struct tmp401_data *data) in tmp401_init_client()
545 struct regmap *regmap = data->regmap; in tmp401_init_client()
564 if (of_property_read_bool(data->client->dev.of_node, "ti,extended-range-enable")) { in tmp401_init_client()
569 data->extended_range = !!(config & TMP401_CONFIG_RANGE); in tmp401_init_client()
577 ret = of_property_read_u32(data->client->dev.of_node, "ti,n-factor", &nfactor); in tmp401_init_client()
579 if (data->kind == tmp401) { in tmp401_init_client()
580 dev_err(&data->client->dev, "ti,tmp401 does not support n-factor correction\n"); in tmp401_init_client()
581 return -EINVAL; in tmp401_init_client()
583 if (nfactor < -128 || nfactor > 127) { in tmp401_init_client()
584 dev_err(&data->client->dev, "n-factor is invalid (%d)\n", nfactor); in tmp401_init_client()
585 return -EINVAL; in tmp401_init_client()
592 ret = of_property_read_u32(data->client->dev.of_node, "ti,beta-compensation", &val); in tmp401_init_client()
594 if (data->kind == tmp401 || data->kind == tmp411) { in tmp401_init_client()
595 dev_err(&data->client->dev, "ti,tmp401 or ti,tmp411 does not support beta compensation\n"); in tmp401_init_client()
596 return -EINVAL; in tmp401_init_client()
599 dev_err(&data->client->dev, "beta-compensation is invalid (%u)\n", val); in tmp401_init_client()
600 return -EINVAL; in tmp401_init_client()
610 static int tmp401_detect(struct i2c_client *client, in tmp401_detect()
614 struct i2c_adapter *adapter = client->adapter; in tmp401_detect()
618 return -ENODEV; in tmp401_detect()
623 return -ENODEV; in tmp401_detect()
629 if (client->addr != 0x4c) in tmp401_detect()
630 return -ENODEV; in tmp401_detect()
634 if (client->addr != 0x4c) in tmp401_detect()
635 return -ENODEV; in tmp401_detect()
639 if (client->addr != 0x4d) in tmp401_detect()
640 return -ENODEV; in tmp401_detect()
644 if (client->addr != 0x4e) in tmp401_detect()
645 return -ENODEV; in tmp401_detect()
649 if (client->addr != 0x4c && client->addr != 0x4d) in tmp401_detect()
650 return -ENODEV; in tmp401_detect()
654 if (client->addr != 0x4c && client->addr != 0x4d) in tmp401_detect()
655 return -ENODEV; in tmp401_detect()
662 return -ENODEV; in tmp401_detect()
667 return -ENODEV; in tmp401_detect()
670 /* Datasheet says: 0x1-0x6 */ in tmp401_detect()
672 return -ENODEV; in tmp401_detect()
674 strscpy(info->type, tmp401_id[kind].name, I2C_NAME_SIZE); in tmp401_detect()
679 static int tmp401_probe(struct i2c_client *client) in tmp401_probe()
681 static const char * const names[] = { in tmp401_probe()
684 struct device *dev = &client->dev; in tmp401_probe()
692 return -ENOMEM; in tmp401_probe()
694 data->client = client; in tmp401_probe()
695 mutex_init(&data->update_lock); in tmp401_probe()
696 data->kind = i2c_match_id(tmp401_id, client)->driver_data; in tmp401_probe()
698 data->regmap = devm_regmap_init(dev, NULL, data, &tmp401_regmap_config); in tmp401_probe()
699 if (IS_ERR(data->regmap)) in tmp401_probe()
700 return PTR_ERR(data->regmap); in tmp401_probe()
703 data->chip.ops = &tmp401_ops; in tmp401_probe()
704 data->chip.info = data->info; in tmp401_probe()
706 data->info[0] = &data->chip_info; in tmp401_probe()
707 data->info[1] = &data->temp_info; in tmp401_probe()
709 info = &data->chip_info; in tmp401_probe()
710 info->type = hwmon_chip; in tmp401_probe()
711 info->config = data->chip_channel_config; in tmp401_probe()
713 data->chip_channel_config[0] = HWMON_C_UPDATE_INTERVAL; in tmp401_probe()
715 info = &data->temp_info; in tmp401_probe()
716 info->type = hwmon_temp; in tmp401_probe()
717 info->config = data->temp_channel_config; in tmp401_probe()
719 data->temp_channel_config[0] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in tmp401_probe()
722 data->temp_channel_config[1] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in tmp401_probe()
726 if (data->kind == tmp411) { in tmp401_probe()
727 data->temp_channel_config[0] |= HWMON_T_HIGHEST | HWMON_T_LOWEST; in tmp401_probe()
728 data->temp_channel_config[1] |= HWMON_T_HIGHEST | HWMON_T_LOWEST; in tmp401_probe()
729 data->chip_channel_config[0] |= HWMON_C_TEMP_RESET_HISTORY; in tmp401_probe()
732 if (data->kind == tmp432) { in tmp401_probe()
733 data->temp_channel_config[2] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in tmp401_probe()
743 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, in tmp401_probe()
744 &data->chip, NULL); in tmp401_probe()
748 dev_info(dev, "Detected TI %s chip\n", names[data->kind]); in tmp401_probe()
753 static const struct of_device_id __maybe_unused tmp4xx_of_match[] = {
763 static struct i2c_driver tmp401_driver = {