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()
327 *val = tmp401_register_to_temp(regval, data->extended_range); in tmp401_temp_read()
333 *val = tmp401_register_to_temp(regvals[0], data->extended_range) - in tmp401_temp_read()
347 return -EOPNOTSUPP; in tmp401_temp_read()
352 static int tmp401_temp_write(struct device *dev, u32 attr, int channel, in tmp401_temp_write()
356 struct regmap *regmap = data->regmap; in tmp401_temp_write()
360 mutex_lock(&data->update_lock); in tmp401_temp_write()
366 regval = tmp401_temp_to_register(val, data->extended_range, in tmp401_temp_write()
371 if (data->extended_range) in tmp401_temp_write()
372 val = clamp_val(val, -64000, 191000); in tmp401_temp_write()
380 temp = tmp401_register_to_temp(regval, data->extended_range); in tmp401_temp_write()
381 val = clamp_val(val, temp - 255000, temp); in tmp401_temp_write()
382 regval = ((temp - val) + 500) / 1000; in tmp401_temp_write()
386 ret = -EOPNOTSUPP; in tmp401_temp_write()
389 mutex_unlock(&data->update_lock); in tmp401_temp_write()
393 static int tmp401_chip_read(struct device *dev, u32 attr, int channel, long *val) in tmp401_chip_read()
401 ret = regmap_read(data->regmap, TMP401_CONVERSION_RATE, &regval); in tmp401_chip_read()
404 *val = (1 << (7 - regval)) * 125; in tmp401_chip_read()
410 return -EOPNOTSUPP; in tmp401_chip_read()
416 static int tmp401_set_convrate(struct regmap *regmap, long val) in tmp401_set_convrate()
422 * interval = (1 << (7 - rate)) * 125; in tmp401_set_convrate()
424 * rate = 7 - __fls(interval * 4 / (125 * 3)); in tmp401_set_convrate()
429 rate = 7 - __fls(val * 4 / (125 * 3)); in tmp401_set_convrate()
433 static int tmp401_chip_write(struct device *dev, u32 attr, int channel, long val) in tmp401_chip_write()
436 struct regmap *regmap = data->regmap; in tmp401_chip_write()
439 mutex_lock(&data->update_lock); in tmp401_chip_write()
446 err = -EINVAL; in tmp401_chip_write()
451 * minimum/maximum registers (0x30-0x37). in tmp401_chip_write()
456 err = -EOPNOTSUPP; in tmp401_chip_write()
459 mutex_unlock(&data->update_lock); in tmp401_chip_write()
464 static int tmp401_read(struct device *dev, enum hwmon_sensor_types type, in tmp401_read()
473 return -EOPNOTSUPP; in tmp401_read()
477 static int tmp401_write(struct device *dev, enum hwmon_sensor_types type, in tmp401_write()
486 return -EOPNOTSUPP; in tmp401_write()
490 static umode_t tmp401_is_visible(const void *data, enum hwmon_sensor_types type, in tmp401_is_visible()
528 static const struct hwmon_ops tmp401_ops = {
536 static int tmp401_init_client(struct tmp401_data *data) in tmp401_init_client()
538 struct regmap *regmap = data->regmap; in tmp401_init_client()
557 if (of_property_read_bool(data->client->dev.of_node, "ti,extended-range-enable")) { in tmp401_init_client()
562 data->extended_range = !!(config & TMP401_CONFIG_RANGE); in tmp401_init_client()
570 ret = of_property_read_u32(data->client->dev.of_node, "ti,n-factor", &nfactor); in tmp401_init_client()
572 if (data->kind == tmp401) { in tmp401_init_client()
573 dev_err(&data->client->dev, "ti,tmp401 does not support n-factor correction\n"); in tmp401_init_client()
574 return -EINVAL; in tmp401_init_client()
576 if (nfactor < -128 || nfactor > 127) { in tmp401_init_client()
577 dev_err(&data->client->dev, "n-factor is invalid (%d)\n", nfactor); in tmp401_init_client()
578 return -EINVAL; in tmp401_init_client()
585 ret = of_property_read_u32(data->client->dev.of_node, "ti,beta-compensation", &val); in tmp401_init_client()
587 if (data->kind == tmp401 || data->kind == tmp411) { in tmp401_init_client()
588 dev_err(&data->client->dev, "ti,tmp401 or ti,tmp411 does not support beta compensation\n"); in tmp401_init_client()
589 return -EINVAL; in tmp401_init_client()
592 dev_err(&data->client->dev, "beta-compensation is invalid (%u)\n", val); in tmp401_init_client()
593 return -EINVAL; in tmp401_init_client()
603 static int tmp401_detect(struct i2c_client *client, in tmp401_detect()
607 struct i2c_adapter *adapter = client->adapter; in tmp401_detect()
611 return -ENODEV; in tmp401_detect()
616 return -ENODEV; in tmp401_detect()
622 if (client->addr != 0x4c) in tmp401_detect()
623 return -ENODEV; in tmp401_detect()
627 if (client->addr != 0x4c) in tmp401_detect()
628 return -ENODEV; in tmp401_detect()
632 if (client->addr != 0x4d) in tmp401_detect()
633 return -ENODEV; in tmp401_detect()
637 if (client->addr != 0x4e) in tmp401_detect()
638 return -ENODEV; in tmp401_detect()
642 if (client->addr != 0x4c && client->addr != 0x4d) in tmp401_detect()
643 return -ENODEV; in tmp401_detect()
647 if (client->addr != 0x4c && client->addr != 0x4d) in tmp401_detect()
648 return -ENODEV; in tmp401_detect()
655 return -ENODEV; in tmp401_detect()
660 return -ENODEV; in tmp401_detect()
663 /* Datasheet says: 0x1-0x6 */ in tmp401_detect()
665 return -ENODEV; in tmp401_detect()
667 strscpy(info->type, tmp401_id[kind].name, I2C_NAME_SIZE); in tmp401_detect()
672 static int tmp401_probe(struct i2c_client *client) in tmp401_probe()
674 static const char * const names[] = { in tmp401_probe()
677 struct device *dev = &client->dev; in tmp401_probe()
685 return -ENOMEM; in tmp401_probe()
687 data->client = client; in tmp401_probe()
688 mutex_init(&data->update_lock); in tmp401_probe()
689 data->kind = (uintptr_t)i2c_get_match_data(client); in tmp401_probe()
691 data->regmap = devm_regmap_init(dev, NULL, data, &tmp401_regmap_config); in tmp401_probe()
692 if (IS_ERR(data->regmap)) in tmp401_probe()
693 return PTR_ERR(data->regmap); in tmp401_probe()
696 data->chip.ops = &tmp401_ops; in tmp401_probe()
697 data->chip.info = data->info; in tmp401_probe()
699 data->info[0] = &data->chip_info; in tmp401_probe()
700 data->info[1] = &data->temp_info; in tmp401_probe()
702 info = &data->chip_info; in tmp401_probe()
703 info->type = hwmon_chip; in tmp401_probe()
704 info->config = data->chip_channel_config; in tmp401_probe()
706 data->chip_channel_config[0] = HWMON_C_UPDATE_INTERVAL; in tmp401_probe()
708 info = &data->temp_info; in tmp401_probe()
709 info->type = hwmon_temp; in tmp401_probe()
710 info->config = data->temp_channel_config; in tmp401_probe()
712 data->temp_channel_config[0] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in tmp401_probe()
715 data->temp_channel_config[1] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in tmp401_probe()
719 if (data->kind == tmp411) { in tmp401_probe()
720 data->temp_channel_config[0] |= HWMON_T_HIGHEST | HWMON_T_LOWEST; in tmp401_probe()
721 data->temp_channel_config[1] |= HWMON_T_HIGHEST | HWMON_T_LOWEST; in tmp401_probe()
722 data->chip_channel_config[0] |= HWMON_C_TEMP_RESET_HISTORY; in tmp401_probe()
725 if (data->kind == tmp432) { in tmp401_probe()
726 data->temp_channel_config[2] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in tmp401_probe()
736 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, in tmp401_probe()
737 &data->chip, NULL); in tmp401_probe()
741 dev_info(dev, "Detected TI %s chip\n", names[data->kind]); in tmp401_probe()
746 static const struct of_device_id __maybe_unused tmp4xx_of_match[] = {
756 static struct i2c_driver tmp401_driver = {