Lines Matching +full:alert +full:- +full:celsius

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
5 * Copyright (C) 2003-2010 Jean Delvare <jdelvare@suse.de>
10 * temperature) and a 3-4 deg accuracy.
18 * When device is auto-detected, the driver will assume an LM99.
68 * pin-compatible with the LM86, the ED/EDP parts are also address-compatible.
100 * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, ADT7461A, MAX6649,
102 * ADM1032-2, ADT7461-2, ADT7461A-2, LM89-1, LM99-1, MAX6646, and NCT1008D
189 #define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert */
352 u16 alert_alarms; /* Which alarm bits trigger ALERT# */
511 u16 alert_alarms; /* Which alarm bits trigger ALERT# */
533 return i2c_smbus_xfer(client->adapter, client->addr, in adm1032_write_byte()
534 client->flags & ~I2C_CLIENT_PEC, in adm1032_write_byte()
539 * It is assumed that client->update_lock is held (unless we are in
548 if (client->flags & I2C_CLIENT_PEC) { in lm90_read_reg()
566 * the one-shot conversion register, which we don't want to do in lm90_read16()
594 if (data->config != config) { in lm90_update_confreg()
597 err = i2c_smbus_write_byte_data(data->client, in lm90_update_confreg()
602 data->config = config; in lm90_update_confreg()
608 * client->update_lock must be held when calling this function (unless we are
610 * than channel 0 is selected. Also, calling code must make sure to re-select
613 * non-default remote channel.
619 if (data->kind == max6696) { in lm90_select_remote_channel()
620 u8 config = data->config & ~0x08; in lm90_select_remote_channel()
631 u8 config = data->config; in lm90_write_convrate()
635 if (data->flags & LM90_PAUSE_FOR_CONFIG) { in lm90_write_convrate()
642 err = i2c_smbus_write_byte_data(data->client, LM90_REG_W_CONVRATE, val); in lm90_write_convrate()
652 * client->update_lock must be held when calling this function (unless we are
666 i < data->max_convrate; i++, update_interval >>= 1) in lm90_set_convrate()
671 data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64); in lm90_set_convrate()
678 struct i2c_client *client = data->client; in lm90_update_limits()
681 if (data->flags & LM90_HAVE_CRIT) { in lm90_update_limits()
685 data->temp8[LOCAL_CRIT] = val; in lm90_update_limits()
690 data->temp8[REMOTE_CRIT] = val; in lm90_update_limits()
695 data->temp_hyst = val; in lm90_update_limits()
701 data->temp11[REMOTE_LOW] = val << 8; in lm90_update_limits()
703 if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { in lm90_update_limits()
707 data->temp11[REMOTE_LOW] |= val; in lm90_update_limits()
713 data->temp11[REMOTE_HIGH] = val << 8; in lm90_update_limits()
715 if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { in lm90_update_limits()
719 data->temp11[REMOTE_HIGH] |= val; in lm90_update_limits()
722 if (data->flags & LM90_HAVE_OFFSET) { in lm90_update_limits()
727 data->temp11[REMOTE_OFFSET] = val; in lm90_update_limits()
730 if (data->flags & LM90_HAVE_EMERGENCY) { in lm90_update_limits()
734 data->temp8[LOCAL_EMERG] = val; in lm90_update_limits()
739 data->temp8[REMOTE_EMERG] = val; in lm90_update_limits()
742 if (data->kind == max6696) { in lm90_update_limits()
750 data->temp8[REMOTE2_CRIT] = val; in lm90_update_limits()
755 data->temp8[REMOTE2_EMERG] = val; in lm90_update_limits()
760 data->temp11[REMOTE2_LOW] = val << 8; in lm90_update_limits()
765 data->temp11[REMOTE2_HIGH] = val << 8; in lm90_update_limits()
776 struct i2c_client *client = data->client; in lm90_update_device()
780 if (!data->valid) { in lm90_update_device()
786 next_update = data->last_updated + in lm90_update_device()
787 msecs_to_jiffies(data->update_interval); in lm90_update_device()
788 if (time_after(jiffies, next_update) || !data->valid) { in lm90_update_device()
789 dev_dbg(&client->dev, "Updating lm90 data.\n"); in lm90_update_device()
791 data->valid = false; in lm90_update_device()
796 data->temp8[LOCAL_LOW] = val; in lm90_update_device()
801 data->temp8[LOCAL_HIGH] = val; in lm90_update_device()
803 if (data->reg_local_ext) { in lm90_update_device()
805 data->reg_local_ext); in lm90_update_device()
808 data->temp11[LOCAL_TEMP] = val; in lm90_update_device()
813 data->temp11[LOCAL_TEMP] = val << 8; in lm90_update_device()
819 data->temp11[REMOTE_TEMP] = val; in lm90_update_device()
824 data->alarms = val & ~LM90_STATUS_BUSY; in lm90_update_device()
826 if (data->kind == max6696) { in lm90_update_device()
837 data->temp11[REMOTE2_TEMP] = val; in lm90_update_device()
844 data->alarms |= val << 8; in lm90_update_device()
848 * Re-enable ALERT# output if it was originally enabled and in lm90_update_device()
851 if (!(data->config_orig & 0x80) && in lm90_update_device()
852 !(data->alarms & data->alert_alarms)) { in lm90_update_device()
853 if (data->config & 0x80) { in lm90_update_device()
854 dev_dbg(&client->dev, "Re-enabling ALERT#\n"); in lm90_update_device()
855 lm90_update_confreg(data, data->config & ~0x80); in lm90_update_device()
859 data->last_updated = jiffies; in lm90_update_device()
860 data->valid = true; in lm90_update_device()
869 * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius.
870 * For remote temperatures and limits, it uses signed 11-bit values with
871 * LSB = 0.125 degree Celsius, left-justified in 16-bit registers. Some
897 if (val <= -128000) in temp_to_s8()
898 return -128; in temp_to_s8()
902 return (val - 500) / 1000; in temp_to_s8()
917 if (val <= -128000) in temp_to_s16()
922 return (val - 62) / 125 * 32; in temp_to_s16()
941 * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC.
945 if (data->flags & LM90_FLAG_ADT7461_EXT) in temp_from_u8_adt7461()
946 return (val - 64) * 1000; in temp_from_u8_adt7461()
952 if (data->flags & LM90_FLAG_ADT7461_EXT) in temp_from_u16_adt7461()
953 return (val - 0x4000) / 64 * 250; in temp_from_u16_adt7461()
959 if (data->flags & LM90_FLAG_ADT7461_EXT) { in temp_to_u8_adt7461()
960 if (val <= -64000) in temp_to_u8_adt7461()
975 if (data->flags & LM90_FLAG_ADT7461_EXT) { in temp_to_u16_adt7461()
976 if (val <= -64000) in temp_to_u16_adt7461()
995 return sprintf(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC)); in pec_show()
1011 client->flags &= ~I2C_CLIENT_PEC; in pec_store()
1014 client->flags |= I2C_CLIENT_PEC; in pec_store()
1017 return -EINVAL; in pec_store()
1027 s16 temp11 = data->temp11[index]; in lm90_get_temp11()
1030 if (data->flags & LM90_HAVE_EXTENDED_TEMP) in lm90_get_temp11()
1032 else if (data->kind == max6646) in lm90_get_temp11()
1038 if (data->kind == lm99 && index <= 2) in lm90_get_temp11()
1056 struct i2c_client *client = data->client; in lm90_set_temp11()
1061 if (data->kind == lm99 && index <= 2) in lm90_set_temp11()
1062 val -= 16000; in lm90_set_temp11()
1064 if (data->flags & LM90_HAVE_EXTENDED_TEMP) in lm90_set_temp11()
1065 data->temp11[index] = temp_to_u16_adt7461(data, val); in lm90_set_temp11()
1066 else if (data->kind == max6646) in lm90_set_temp11()
1067 data->temp11[index] = temp_to_u8(val) << 8; in lm90_set_temp11()
1068 else if (data->flags & LM90_HAVE_REM_LIMIT_EXT) in lm90_set_temp11()
1069 data->temp11[index] = temp_to_s16(val); in lm90_set_temp11()
1071 data->temp11[index] = temp_to_s8(val) << 8; in lm90_set_temp11()
1074 err = i2c_smbus_write_byte_data(client, regp->high, in lm90_set_temp11()
1075 data->temp11[index] >> 8); in lm90_set_temp11()
1078 if (data->flags & LM90_HAVE_REM_LIMIT_EXT) in lm90_set_temp11()
1079 err = i2c_smbus_write_byte_data(client, regp->low, in lm90_set_temp11()
1080 data->temp11[index] & 0xff); in lm90_set_temp11()
1088 s8 temp8 = data->temp8[index]; in lm90_get_temp8()
1091 if (data->flags & LM90_HAVE_EXTENDED_TEMP) in lm90_get_temp8()
1093 else if (data->kind == max6646) in lm90_get_temp8()
1099 if (data->kind == lm99 && index == 3) in lm90_get_temp8()
1117 struct i2c_client *client = data->client; in lm90_set_temp8()
1121 if (data->kind == lm99 && index == 3) in lm90_set_temp8()
1122 val -= 16000; in lm90_set_temp8()
1124 if (data->flags & LM90_HAVE_EXTENDED_TEMP) in lm90_set_temp8()
1125 data->temp8[index] = temp_to_u8_adt7461(data, val); in lm90_set_temp8()
1126 else if (data->kind == max6646) in lm90_set_temp8()
1127 data->temp8[index] = temp_to_u8(val); in lm90_set_temp8()
1129 data->temp8[index] = temp_to_s8(val); in lm90_set_temp8()
1132 err = i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]); in lm90_set_temp8()
1142 if (data->flags & LM90_HAVE_EXTENDED_TEMP) in lm90_get_temphyst()
1143 temp = temp_from_u8_adt7461(data, data->temp8[index]); in lm90_get_temphyst()
1144 else if (data->kind == max6646) in lm90_get_temphyst()
1145 temp = temp_from_u8(data->temp8[index]); in lm90_get_temphyst()
1147 temp = temp_from_s8(data->temp8[index]); in lm90_get_temphyst()
1150 if (data->kind == lm99 && index == 3) in lm90_get_temphyst()
1153 return temp - temp_from_s8(data->temp_hyst); in lm90_get_temphyst()
1158 struct i2c_client *client = data->client; in lm90_set_temphyst()
1162 if (data->flags & LM90_HAVE_EXTENDED_TEMP) in lm90_set_temphyst()
1163 temp = temp_from_u8_adt7461(data, data->temp8[LOCAL_CRIT]); in lm90_set_temphyst()
1164 else if (data->kind == max6646) in lm90_set_temphyst()
1165 temp = temp_from_u8(data->temp8[LOCAL_CRIT]); in lm90_set_temphyst()
1167 temp = temp_from_s8(data->temp8[LOCAL_CRIT]); in lm90_set_temphyst()
1169 data->temp_hyst = hyst_to_reg(temp - val); in lm90_set_temphyst()
1171 data->temp_hyst); in lm90_set_temphyst()
1207 mutex_lock(&data->update_lock); in lm90_temp_read()
1209 mutex_unlock(&data->update_lock); in lm90_temp_read()
1218 *val = (data->alarms >> lm90_min_alarm_bits[channel]) & 1; in lm90_temp_read()
1221 *val = (data->alarms >> lm90_max_alarm_bits[channel]) & 1; in lm90_temp_read()
1224 if (data->flags & LM90_HAVE_CRIT_ALRM_SWP) in lm90_temp_read()
1225 *val = (data->alarms >> lm90_crit_alarm_bits_swapped[channel]) & 1; in lm90_temp_read()
1227 *val = (data->alarms >> lm90_crit_alarm_bits[channel]) & 1; in lm90_temp_read()
1230 *val = (data->alarms >> lm90_emergency_alarm_bits[channel]) & 1; in lm90_temp_read()
1233 *val = (data->alarms >> lm90_fault_bits[channel]) & 1; in lm90_temp_read()
1267 return -EOPNOTSUPP; in lm90_temp_read()
1277 mutex_lock(&data->update_lock); in lm90_temp_write()
1317 err = -EOPNOTSUPP; in lm90_temp_write()
1321 mutex_unlock(&data->update_lock); in lm90_temp_write()
1357 mutex_lock(&data->update_lock); in lm90_chip_read()
1359 mutex_unlock(&data->update_lock); in lm90_chip_read()
1365 *val = data->update_interval; in lm90_chip_read()
1368 *val = data->alarms; in lm90_chip_read()
1371 return -EOPNOTSUPP; in lm90_chip_read()
1380 struct i2c_client *client = data->client; in lm90_chip_write()
1383 mutex_lock(&data->update_lock); in lm90_chip_write()
1395 err = -EOPNOTSUPP; in lm90_chip_write()
1399 mutex_unlock(&data->update_lock); in lm90_chip_write()
1425 return -EOPNOTSUPP; in lm90_read()
1438 return -EOPNOTSUPP; in lm90_write()
1455 /* Return 0 if detection is successful, -ENODEV otherwise */
1459 struct i2c_adapter *adapter = client->adapter; in lm90_detect()
1460 int address = client->addr; in lm90_detect()
1465 return -ENODEV; in lm90_detect()
1473 return -ENODEV; in lm90_detect()
1478 return -ENODEV; in lm90_detect()
1492 dev_info(&adapter->dev, in lm90_detect()
1495 dev_info(&adapter->dev, in lm90_detect()
1518 info->flags |= I2C_CLIENT_PEC; in lm90_detect()
1535 * We read MAX6659_REG_R_REMOTE_EMERG twice, and re-read in lm90_detect()
1549 return -ENODEV; in lm90_detect()
1561 * For this reason it will be mis-detected as MAX6657 if its in lm90_detect()
1676 dev_dbg(&adapter->dev, in lm90_detect()
1679 return -ENODEV; in lm90_detect()
1682 strlcpy(info->type, name, I2C_NAME_SIZE); in lm90_detect()
1690 struct i2c_client *client = data->client; in lm90_restore_conf()
1693 lm90_write_convrate(data, data->convrate_orig); in lm90_restore_conf()
1695 data->config_orig); in lm90_restore_conf()
1705 data->convrate_orig = convrate; in lm90_init_client()
1713 data->config_orig = config; in lm90_init_client()
1714 data->config = config; in lm90_init_client()
1719 if (data->flags & LM90_HAVE_EXTENDED_TEMP) { in lm90_init_client()
1721 data->flags |= LM90_FLAG_ADT7461_EXT; in lm90_init_client()
1727 * to -64 degree) mode for the remote temperature sensor. in lm90_init_client()
1729 if (data->kind == max6680) in lm90_init_client()
1734 * 0 degrees to -64 degrees). Note that extended resolution is not in lm90_init_client()
1738 if (data->kind == max6654) in lm90_init_client()
1744 if (data->kind == max6696) in lm90_init_client()
1750 return devm_add_action_or_reset(&client->dev, lm90_restore_conf, data); in lm90_init_client()
1762 if (data->kind == max6696) { in lm90_is_tripped()
1775 dev_warn(&client->dev, in lm90_is_tripped()
1779 dev_warn(&client->dev, in lm90_is_tripped()
1782 dev_warn(&client->dev, in lm90_is_tripped()
1786 dev_warn(&client->dev, in lm90_is_tripped()
1789 dev_warn(&client->dev, in lm90_is_tripped()
1825 struct device *dev = &client->dev; in lm90_probe()
1826 struct i2c_adapter *adapter = client->adapter; in lm90_probe()
1849 return -ENOMEM; in lm90_probe()
1851 data->client = client; in lm90_probe()
1853 mutex_init(&data->update_lock); in lm90_probe()
1856 if (client->dev.of_node) in lm90_probe()
1857 data->kind = (enum chips)of_device_get_match_data(&client->dev); in lm90_probe()
1859 data->kind = i2c_match_id(lm90_id, client)->driver_data; in lm90_probe()
1860 if (data->kind == adm1032) { in lm90_probe()
1862 client->flags &= ~I2C_CLIENT_PEC; in lm90_probe()
1867 * ALERT# output in lm90_probe()
1869 data->alert_alarms = lm90_params[data->kind].alert_alarms; in lm90_probe()
1872 data->flags = lm90_params[data->kind].flags; in lm90_probe()
1874 data->chip.ops = &lm90_ops; in lm90_probe()
1875 data->chip.info = data->info; in lm90_probe()
1877 data->info[0] = HWMON_CHANNEL_INFO(chip, in lm90_probe()
1879 data->info[1] = &data->temp_info; in lm90_probe()
1881 info = &data->temp_info; in lm90_probe()
1882 info->type = hwmon_temp; in lm90_probe()
1883 info->config = data->channel_config; in lm90_probe()
1885 data->channel_config[0] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in lm90_probe()
1887 data->channel_config[1] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in lm90_probe()
1890 if (data->flags & LM90_HAVE_CRIT) { in lm90_probe()
1891 data->channel_config[0] |= HWMON_T_CRIT | HWMON_T_CRIT_ALARM | HWMON_T_CRIT_HYST; in lm90_probe()
1892 data->channel_config[1] |= HWMON_T_CRIT | HWMON_T_CRIT_ALARM | HWMON_T_CRIT_HYST; in lm90_probe()
1895 if (data->flags & LM90_HAVE_OFFSET) in lm90_probe()
1896 data->channel_config[1] |= HWMON_T_OFFSET; in lm90_probe()
1898 if (data->flags & LM90_HAVE_EMERGENCY) { in lm90_probe()
1899 data->channel_config[0] |= HWMON_T_EMERGENCY | in lm90_probe()
1901 data->channel_config[1] |= HWMON_T_EMERGENCY | in lm90_probe()
1905 if (data->flags & LM90_HAVE_EMERGENCY_ALARM) { in lm90_probe()
1906 data->channel_config[0] |= HWMON_T_EMERGENCY_ALARM; in lm90_probe()
1907 data->channel_config[1] |= HWMON_T_EMERGENCY_ALARM; in lm90_probe()
1910 if (data->flags & LM90_HAVE_TEMP3) { in lm90_probe()
1911 data->channel_config[2] = HWMON_T_INPUT | in lm90_probe()
1920 data->reg_local_ext = lm90_params[data->kind].reg_local_ext; in lm90_probe()
1923 data->max_convrate = lm90_params[data->kind].max_convrate; in lm90_probe()
1936 if (client->flags & I2C_CLIENT_PEC) { in lm90_probe()
1945 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in lm90_probe()
1946 data, &data->chip, in lm90_probe()
1951 if (client->irq) { in lm90_probe()
1952 dev_dbg(dev, "IRQ: %d\n", client->irq); in lm90_probe()
1953 err = devm_request_threaded_irq(dev, client->irq, in lm90_probe()
1958 dev_err(dev, "cannot request IRQ %d\n", client->irq); in lm90_probe()
1976 * Disable ALERT# output, because these chips don't implement in lm90_alert()
1977 * SMBus alert correctly; they should only hold the alert line in lm90_alert()
1982 if ((data->flags & LM90_HAVE_BROKEN_ALERT) && in lm90_alert()
1983 (alarms & data->alert_alarms)) { in lm90_alert()
1984 dev_dbg(&client->dev, "Disabling ALERT#\n"); in lm90_alert()
1985 lm90_update_confreg(data, data->config | 0x80); in lm90_alert()
1988 dev_info(&client->dev, "Everything OK\n"); in lm90_alert()
1999 .alert = lm90_alert,