Lines Matching +full:rate +full:- +full:lp +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0-or-later
8 * Lionel Pouliquen <lionel.lp.pouliquen@nokia.com>
24 #define TMP464_NUM_CHANNELS 5 /* chan 0 is internal, 1-4 are remote */
25 #define TMP468_NUM_CHANNELS 9 /* chan 0 is internal, 1-8 are remote */
30 #define TMP464_TEMP_OFFSET_REG(channel) (0x40 + ((channel) - 1) * 8)
31 #define TMP464_N_FACTOR_REG(channel) (0x41 + ((channel) - 1) * 8)
122 struct regmap *regmap = data->regmap; in tmp464_enable_channels()
126 for (i = 0; i < data->channels; i++) in tmp464_enable_channels()
127 if (data->channel[i].enabled) in tmp464_enable_channels()
139 *val = data->update_interval; in tmp464_chip_read()
142 return -EOPNOTSUPP; in tmp464_chip_read()
149 struct regmap *regmap = data->regmap; in tmp464_temp_read()
175 mutex_lock(&data->update_lock); in tmp464_temp_read()
176 if (!data->valid || time_after(jiffies, data->last_updated + in tmp464_temp_read()
177 msecs_to_jiffies(data->update_interval))) { in tmp464_temp_read()
181 data->open_reg = regval; in tmp464_temp_read()
182 data->last_updated = jiffies; in tmp464_temp_read()
183 data->valid = true; in tmp464_temp_read()
185 *val = !!(data->open_reg & BIT(channel + 7)); in tmp464_temp_read()
187 mutex_unlock(&data->update_lock); in tmp464_temp_read()
195 *val = temp_from_reg(regvals[0] - regvals[1]); in tmp464_temp_read()
209 *val = temp_from_reg(regvals[0] - regvals[1]); in tmp464_temp_read()
224 if (!data->channel[channel].enabled) { in tmp464_temp_read()
225 err = -ENODATA; in tmp464_temp_read()
234 *val = data->channel[channel].enabled; in tmp464_temp_read()
237 err = -EOPNOTSUPP; in tmp464_temp_read()
253 return -EOPNOTSUPP; in tmp464_read()
262 *str = data->channel[channel].label; in tmp464_read_string()
269 int rate; in tmp464_set_convrate() local
272 * For valid rates, interval in milli-seconds can be calculated as in tmp464_set_convrate()
273 * interval = 125 << (7 - rate); in tmp464_set_convrate()
275 * interval = (1 << (7 - rate)) * 125; in tmp464_set_convrate()
276 * The rate is therefore in tmp464_set_convrate()
277 * rate = 7 - __fls(interval / 125); in tmp464_set_convrate()
278 * and the rounded rate is in tmp464_set_convrate()
279 * rate = 7 - __fls(interval * 4 / (125 * 3)); in tmp464_set_convrate()
284 rate = 7 - __fls(interval * 4 / (125 * 3)); in tmp464_set_convrate()
285 data->update_interval = 125 << (7 - rate); in tmp464_set_convrate()
287 return regmap_update_bits(data->regmap, TMP464_CONFIG_REG, in tmp464_set_convrate()
289 rate << TMP464_CONFIG_CONVERSION_RATE_B0); in tmp464_set_convrate()
298 return -EOPNOTSUPP; in tmp464_chip_write()
304 struct regmap *regmap = data->regmap; in tmp464_temp_write()
313 val = clamp_val(val, -256000, 256000); /* prevent overflow/underflow */ in tmp464_temp_write()
314 val = clamp_val(temp_from_reg(regval) - val, 0, 255000); in tmp464_temp_write()
319 val = temp_to_limit_reg(clamp_val(val, -255000, 255500)); in tmp464_temp_write()
323 val = temp_to_limit_reg(clamp_val(val, -255000, 255500)); in tmp464_temp_write()
327 val = temp_to_offset_reg(clamp_val(val, -128000, 127937)); in tmp464_temp_write()
331 data->channel[channel].enabled = !!val; in tmp464_temp_write()
335 err = -EOPNOTSUPP; in tmp464_temp_write()
348 mutex_lock(&data->update_lock); in tmp464_write()
358 err = -EOPNOTSUPP; in tmp464_write()
362 mutex_unlock(&data->update_lock); in tmp464_write()
372 if (channel >= data->channels) in tmp464_is_visible()
396 if (data->channel[channel].label) in tmp464_is_visible()
421 regmap_write(data->regmap, TMP464_CONFIG_REG, data->config_orig); in tmp464_restore_config()
426 struct regmap *regmap = data->regmap; in tmp464_init_client()
447 data->config_orig = regval; in tmp464_init_client()
452 /* Default to 500 ms update interval */ in tmp464_init_client()
460 data->update_interval = 500; in tmp464_init_client()
468 struct i2c_adapter *adapter = client->adapter; in tmp464_detect()
473 return -ENODEV; in tmp464_detect()
479 return -ENODEV; in tmp464_detect()
486 return -ENODEV; in tmp464_detect()
491 return -ENODEV; in tmp464_detect()
506 return -ENODEV; in tmp464_detect()
509 strscpy(info->type, name, I2C_NAME_SIZE); in tmp464_detect()
510 dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n", chip, client->addr); in tmp464_detect()
520 struct regmap *regmap = data->regmap; in tmp464_probe_child_from_dt()
531 if (channel >= data->channels) { in tmp464_probe_child_from_dt()
533 return -EINVAL; in tmp464_probe_child_from_dt()
536 of_property_read_string(child, "label", &data->channel[channel].label); in tmp464_probe_child_from_dt()
538 data->channel[channel].enabled = of_device_is_available(child); in tmp464_probe_child_from_dt()
540 err = of_property_read_s32(child, "ti,n-factor", &nfactor); in tmp464_probe_child_from_dt()
541 if (err && err != -EINVAL) in tmp464_probe_child_from_dt()
545 dev_err(dev, "n-factor can't be set for internal channel\n"); in tmp464_probe_child_from_dt()
546 return -EINVAL; in tmp464_probe_child_from_dt()
548 if (nfactor > 127 || nfactor < -128) { in tmp464_probe_child_from_dt()
549 dev_err(dev, "n-factor for channel %d invalid (%d)\n", in tmp464_probe_child_from_dt()
551 return -EINVAL; in tmp464_probe_child_from_dt()
564 const struct device_node *np = dev->of_node; in tmp464_probe_from_dt()
568 if (strcmp(child->name, "channel")) in tmp464_probe_from_dt()
648 struct device *dev = &client->dev; in tmp464_probe()
653 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) { in tmp464_probe()
654 dev_err(&client->dev, "i2c functionality check failed\n"); in tmp464_probe()
655 return -ENODEV; in tmp464_probe()
659 return -ENOMEM; in tmp464_probe()
661 mutex_init(&data->update_lock); in tmp464_probe()
663 data->channels = (int)(unsigned long)i2c_get_match_data(client); in tmp464_probe()
665 data->regmap = devm_regmap_init_i2c(client, &tmp464_regmap_config); in tmp464_probe()
666 if (IS_ERR(data->regmap)) in tmp464_probe()
667 return PTR_ERR(data->regmap); in tmp464_probe()
669 for (i = 0; i < data->channels; i++) in tmp464_probe()
670 data->channel[i].enabled = true; in tmp464_probe()
676 if (dev->of_node) { in tmp464_probe()
682 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in tmp464_probe()