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()
153 mutex_lock(&data->update_lock); in tmp464_temp_read()
175 if (!data->valid || time_after(jiffies, data->last_updated + in tmp464_temp_read()
176 msecs_to_jiffies(data->update_interval))) { in tmp464_temp_read()
180 data->open_reg = regval; in tmp464_temp_read()
181 data->last_updated = jiffies; in tmp464_temp_read()
182 data->valid = true; in tmp464_temp_read()
184 *val = !!(data->open_reg & BIT(channel + 7)); in tmp464_temp_read()
193 regval -= regval2; in tmp464_temp_read()
209 regval -= regval2; in tmp464_temp_read()
225 if (!data->channel[channel].enabled) { in tmp464_temp_read()
226 err = -ENODATA; in tmp464_temp_read()
235 *val = data->channel[channel].enabled; in tmp464_temp_read()
238 err = -EOPNOTSUPP; in tmp464_temp_read()
242 mutex_unlock(&data->update_lock); in tmp464_temp_read()
256 return -EOPNOTSUPP; in tmp464_read()
265 *str = data->channel[channel].label; in tmp464_read_string()
272 int rate; in tmp464_set_convrate() local
275 * For valid rates, interval in milli-seconds can be calculated as in tmp464_set_convrate()
276 * interval = 125 << (7 - rate); in tmp464_set_convrate()
278 * interval = (1 << (7 - rate)) * 125; in tmp464_set_convrate()
279 * The rate is therefore in tmp464_set_convrate()
280 * rate = 7 - __fls(interval / 125); in tmp464_set_convrate()
281 * and the rounded rate is in tmp464_set_convrate()
282 * rate = 7 - __fls(interval * 4 / (125 * 3)); in tmp464_set_convrate()
287 rate = 7 - __fls(interval * 4 / (125 * 3)); in tmp464_set_convrate()
288 data->update_interval = 125 << (7 - rate); in tmp464_set_convrate()
290 return regmap_update_bits(data->regmap, TMP464_CONFIG_REG, in tmp464_set_convrate()
292 rate << TMP464_CONFIG_CONVERSION_RATE_B0); in tmp464_set_convrate()
301 return -EOPNOTSUPP; in tmp464_chip_write()
307 struct regmap *regmap = data->regmap; in tmp464_temp_write()
316 val = clamp_val(val, -256000, 256000); /* prevent overflow/underflow */ in tmp464_temp_write()
317 val = clamp_val(temp_from_reg(regval) - val, 0, 255000); in tmp464_temp_write()
322 val = temp_to_limit_reg(clamp_val(val, -255000, 255500)); in tmp464_temp_write()
326 val = temp_to_limit_reg(clamp_val(val, -255000, 255500)); in tmp464_temp_write()
330 val = temp_to_offset_reg(clamp_val(val, -128000, 127937)); in tmp464_temp_write()
334 data->channel[channel].enabled = !!val; in tmp464_temp_write()
338 err = -EOPNOTSUPP; in tmp464_temp_write()
351 mutex_lock(&data->update_lock); in tmp464_write()
361 err = -EOPNOTSUPP; in tmp464_write()
365 mutex_unlock(&data->update_lock); in tmp464_write()
375 if (channel >= data->channels) in tmp464_is_visible()
399 if (data->channel[channel].label) in tmp464_is_visible()
424 regmap_write(data->regmap, TMP464_CONFIG_REG, data->config_orig); in tmp464_restore_config()
429 struct regmap *regmap = data->regmap; in tmp464_init_client()
450 data->config_orig = regval; in tmp464_init_client()
455 /* Default to 500 ms update interval */ in tmp464_init_client()
463 data->update_interval = 500; in tmp464_init_client()
471 struct i2c_adapter *adapter = client->adapter; in tmp464_detect()
476 return -ENODEV; in tmp464_detect()
482 return -ENODEV; in tmp464_detect()
489 return -ENODEV; in tmp464_detect()
494 return -ENODEV; in tmp464_detect()
509 return -ENODEV; in tmp464_detect()
512 strscpy(info->type, name, I2C_NAME_SIZE); in tmp464_detect()
513 dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n", chip, client->addr); in tmp464_detect()
523 struct regmap *regmap = data->regmap; in tmp464_probe_child_from_dt()
534 if (channel >= data->channels) { in tmp464_probe_child_from_dt()
536 return -EINVAL; in tmp464_probe_child_from_dt()
539 of_property_read_string(child, "label", &data->channel[channel].label); in tmp464_probe_child_from_dt()
541 data->channel[channel].enabled = of_device_is_available(child); in tmp464_probe_child_from_dt()
543 err = of_property_read_s32(child, "ti,n-factor", &nfactor); in tmp464_probe_child_from_dt()
544 if (err && err != -EINVAL) in tmp464_probe_child_from_dt()
548 dev_err(dev, "n-factor can't be set for internal channel\n"); in tmp464_probe_child_from_dt()
549 return -EINVAL; in tmp464_probe_child_from_dt()
551 if (nfactor > 127 || nfactor < -128) { in tmp464_probe_child_from_dt()
552 dev_err(dev, "n-factor for channel %d invalid (%d)\n", in tmp464_probe_child_from_dt()
554 return -EINVAL; in tmp464_probe_child_from_dt()
567 const struct device_node *np = dev->of_node; in tmp464_probe_from_dt()
572 if (strcmp(child->name, "channel")) in tmp464_probe_from_dt()
654 struct device *dev = &client->dev; in tmp464_probe()
659 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) { in tmp464_probe()
660 dev_err(&client->dev, "i2c functionality check failed\n"); in tmp464_probe()
661 return -ENODEV; in tmp464_probe()
665 return -ENOMEM; in tmp464_probe()
667 mutex_init(&data->update_lock); in tmp464_probe()
669 if (dev->of_node) in tmp464_probe()
670 data->channels = (int)(unsigned long)of_device_get_match_data(&client->dev); in tmp464_probe()
672 data->channels = i2c_match_id(tmp464_id, client)->driver_data; in tmp464_probe()
674 data->regmap = devm_regmap_init_i2c(client, &tmp464_regmap_config); in tmp464_probe()
675 if (IS_ERR(data->regmap)) in tmp464_probe()
676 return PTR_ERR(data->regmap); in tmp464_probe()
678 for (i = 0; i < data->channels; i++) in tmp464_probe()
679 data->channel[i].enabled = true; in tmp464_probe()
685 if (dev->of_node) { in tmp464_probe()
691 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in tmp464_probe()