Lines Matching +full:smbus +full:- +full:timeout +full:- +full:disable
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * jc42.c - driver for Jedec JC42.4 compliant temperature sensors
69 /* SMBUS register */
70 #define SMBUS_STMOUT BIT(7) /* SMBus time-out, active low */
190 #define JC42_TEMP_MIN_EXTENDED (-40000)
219 mutex_lock(&data->update_lock); in jc42_read()
223 ret = regmap_read(data->regmap, JC42_REG_TEMP, ®val); in jc42_read()
230 ret = regmap_read(data->regmap, JC42_REG_TEMP_LOWER, ®val); in jc42_read()
237 ret = regmap_read(data->regmap, JC42_REG_TEMP_UPPER, ®val); in jc42_read()
244 ret = regmap_read(data->regmap, JC42_REG_TEMP_CRITICAL, in jc42_read()
252 ret = regmap_read(data->regmap, JC42_REG_TEMP_UPPER, ®val); in jc42_read()
258 data->config)]; in jc42_read()
259 *val = temp - hyst; in jc42_read()
262 ret = regmap_read(data->regmap, JC42_REG_TEMP_CRITICAL, in jc42_read()
269 data->config)]; in jc42_read()
270 *val = temp - hyst; in jc42_read()
273 ret = regmap_read(data->regmap, JC42_REG_TEMP, ®val); in jc42_read()
280 ret = regmap_read(data->regmap, JC42_REG_TEMP, ®val); in jc42_read()
287 ret = regmap_read(data->regmap, JC42_REG_TEMP, ®val); in jc42_read()
294 ret = -EOPNOTSUPP; in jc42_read()
298 mutex_unlock(&data->update_lock); in jc42_read()
311 mutex_lock(&data->update_lock); in jc42_write()
315 ret = regmap_write(data->regmap, JC42_REG_TEMP_LOWER, in jc42_write()
316 jc42_temp_to_reg(val, data->extended)); in jc42_write()
319 ret = regmap_write(data->regmap, JC42_REG_TEMP_UPPER, in jc42_write()
320 jc42_temp_to_reg(val, data->extended)); in jc42_write()
323 ret = regmap_write(data->regmap, JC42_REG_TEMP_CRITICAL, in jc42_write()
324 jc42_temp_to_reg(val, data->extended)); in jc42_write()
327 ret = regmap_read(data->regmap, JC42_REG_TEMP_CRITICAL, in jc42_write()
336 val = clamp_val(val, (data->extended ? JC42_TEMP_MIN_EXTENDED in jc42_write()
337 : JC42_TEMP_MIN) - 6000, in jc42_write()
339 diff = jc42_temp_from_reg(regval) - val; in jc42_write()
349 data->config = (data->config & ~JC42_CFG_HYST_MASK) | in jc42_write()
351 ret = regmap_write(data->regmap, JC42_REG_CONFIG, in jc42_write()
352 data->config); in jc42_write()
355 ret = -EOPNOTSUPP; in jc42_write()
359 mutex_unlock(&data->update_lock); in jc42_write()
368 unsigned int config = data->config; in jc42_is_visible()
398 /* Return 0 if detection is successful, -ENODEV otherwise */
401 struct i2c_adapter *adapter = client->adapter; in jc42_detect()
406 return -ENODEV; in jc42_detect()
414 return -ENODEV; in jc42_detect()
417 return -ENODEV; in jc42_detect()
421 return -ENODEV; in jc42_detect()
425 if (manid == chip->manid && in jc42_detect()
426 (devid & chip->devid_mask) == chip->devid) { in jc42_detect()
427 strscpy(info->type, "jc42", I2C_NAME_SIZE); in jc42_detect()
431 return -ENODEV; in jc42_detect()
486 struct device *dev = &client->dev; in jc42_probe()
494 return -ENOMEM; in jc42_probe()
496 data->regmap = devm_regmap_init_i2c(client, &jc42_regmap_config); in jc42_probe()
497 if (IS_ERR(data->regmap)) in jc42_probe()
498 return PTR_ERR(data->regmap); in jc42_probe()
501 mutex_init(&data->update_lock); in jc42_probe()
503 ret = regmap_read(data->regmap, JC42_REG_CAP, &cap); in jc42_probe()
507 data->extended = !!(cap & JC42_CAP_RANGE); in jc42_probe()
509 if (device_property_read_bool(dev, "smbus-timeout-disable")) { in jc42_probe()
513 * incompatible with the below attempt to disable in jc42_probe()
514 * the timeout. And the whole thing is opt-in... in jc42_probe()
516 ret = regmap_set_bits(data->regmap, JC42_REG_SMBUS, in jc42_probe()
522 ret = regmap_read(data->regmap, JC42_REG_CONFIG, &config); in jc42_probe()
526 data->orig_config = config; in jc42_probe()
529 regmap_write(data->regmap, JC42_REG_CONFIG, config); in jc42_probe()
531 data->config = config; in jc42_probe()
544 if ((data->config & ~JC42_CFG_HYST_MASK) != in jc42_remove()
545 (data->orig_config & ~JC42_CFG_HYST_MASK)) { in jc42_remove()
548 config = (data->orig_config & ~JC42_CFG_HYST_MASK) in jc42_remove()
549 | (data->config & JC42_CFG_HYST_MASK); in jc42_remove()
550 regmap_write(data->regmap, JC42_REG_CONFIG, config); in jc42_remove()
560 data->config |= JC42_CFG_SHUTDOWN; in jc42_suspend()
561 regmap_write(data->regmap, JC42_REG_CONFIG, data->config); in jc42_suspend()
563 regcache_cache_only(data->regmap, true); in jc42_suspend()
564 regcache_mark_dirty(data->regmap); in jc42_suspend()
573 regcache_cache_only(data->regmap, false); in jc42_resume()
575 data->config &= ~JC42_CFG_SHUTDOWN; in jc42_resume()
576 regmap_write(data->regmap, JC42_REG_CONFIG, data->config); in jc42_resume()
579 return regcache_sync(data->regmap); in jc42_resume()
599 { .compatible = "jedec,jc-42.4-temp", },
620 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");