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.
67 * pin-compatible with the LM86, the ED/EDP parts are also address-compatible.
99 * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, ADT7461A, MAX6649,
101 * ADM1032-2, ADT7461-2, ADT7461A-2, LM89-1, LM99-1, MAX6646, and NCT1008D
184 #define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert */
338 u16 alert_alarms; /* Which alarm bits trigger ALERT# */
484 u16 alert_alarms; /* Which alarm bits trigger ALERT# */
506 return i2c_smbus_xfer(client->adapter, client->addr, in adm1032_write_byte()
507 client->flags & ~I2C_CLIENT_PEC, in adm1032_write_byte()
512 * It is assumed that client->update_lock is held (unless we are in
521 if (client->flags & I2C_CLIENT_PEC) { in lm90_read_reg()
539 * the one-shot conversion register, which we don't want to do in lm90_read16()
567 if (data->config != config) { in lm90_update_confreg()
570 err = i2c_smbus_write_byte_data(data->client, in lm90_update_confreg()
575 data->config = config; in lm90_update_confreg()
581 * client->update_lock must be held when calling this function (unless we are
583 * than channel 0 is selected. Also, calling code must make sure to re-select
586 * non-default remote channel.
592 if (data->kind == max6696) { in lm90_select_remote_channel()
593 u8 config = data->config & ~0x08; in lm90_select_remote_channel()
604 u8 config = data->config; in lm90_write_convrate()
608 if (data->flags & LM90_PAUSE_FOR_CONFIG) { in lm90_write_convrate()
615 err = i2c_smbus_write_byte_data(data->client, LM90_REG_W_CONVRATE, val); in lm90_write_convrate()
625 * client->update_lock must be held when calling this function (unless we are
639 i < data->max_convrate; i++, update_interval >>= 1) in lm90_set_convrate()
644 data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64); in lm90_set_convrate()
651 struct i2c_client *client = data->client; in lm90_update_limits()
657 data->temp8[LOCAL_CRIT] = val; in lm90_update_limits()
662 data->temp8[REMOTE_CRIT] = val; in lm90_update_limits()
667 data->temp_hyst = val; in lm90_update_limits()
672 data->temp11[REMOTE_LOW] = val << 8; in lm90_update_limits()
674 if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { in lm90_update_limits()
678 data->temp11[REMOTE_LOW] |= val; in lm90_update_limits()
684 data->temp11[REMOTE_HIGH] = val << 8; in lm90_update_limits()
686 if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { in lm90_update_limits()
690 data->temp11[REMOTE_HIGH] |= val; in lm90_update_limits()
693 if (data->flags & LM90_HAVE_OFFSET) { in lm90_update_limits()
698 data->temp11[REMOTE_OFFSET] = val; in lm90_update_limits()
701 if (data->flags & LM90_HAVE_EMERGENCY) { in lm90_update_limits()
705 data->temp8[LOCAL_EMERG] = val; in lm90_update_limits()
710 data->temp8[REMOTE_EMERG] = val; in lm90_update_limits()
713 if (data->kind == max6696) { in lm90_update_limits()
721 data->temp8[REMOTE2_CRIT] = val; in lm90_update_limits()
726 data->temp8[REMOTE2_EMERG] = val; in lm90_update_limits()
731 data->temp11[REMOTE2_LOW] = val << 8; in lm90_update_limits()
736 data->temp11[REMOTE2_HIGH] = val << 8; in lm90_update_limits()
747 struct i2c_client *client = data->client; in lm90_update_device()
751 if (!data->valid) { in lm90_update_device()
757 next_update = data->last_updated + in lm90_update_device()
758 msecs_to_jiffies(data->update_interval); in lm90_update_device()
759 if (time_after(jiffies, next_update) || !data->valid) { in lm90_update_device()
760 dev_dbg(&client->dev, "Updating lm90 data.\n"); in lm90_update_device()
762 data->valid = false; in lm90_update_device()
767 data->temp8[LOCAL_LOW] = val; in lm90_update_device()
772 data->temp8[LOCAL_HIGH] = val; in lm90_update_device()
774 if (data->reg_local_ext) { in lm90_update_device()
776 data->reg_local_ext); in lm90_update_device()
779 data->temp11[LOCAL_TEMP] = val; in lm90_update_device()
784 data->temp11[LOCAL_TEMP] = val << 8; in lm90_update_device()
790 data->temp11[REMOTE_TEMP] = val; in lm90_update_device()
795 data->alarms = val; /* lower 8 bit of alarms */ in lm90_update_device()
797 if (data->kind == max6696) { in lm90_update_device()
808 data->temp11[REMOTE2_TEMP] = val; in lm90_update_device()
815 data->alarms |= val << 8; in lm90_update_device()
819 * Re-enable ALERT# output if it was originally enabled and in lm90_update_device()
822 if (!(data->config_orig & 0x80) && in lm90_update_device()
823 !(data->alarms & data->alert_alarms)) { in lm90_update_device()
824 if (data->config & 0x80) { in lm90_update_device()
825 dev_dbg(&client->dev, "Re-enabling ALERT#\n"); in lm90_update_device()
826 lm90_update_confreg(data, data->config & ~0x80); in lm90_update_device()
830 data->last_updated = jiffies; in lm90_update_device()
831 data->valid = true; in lm90_update_device()
840 * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius.
841 * For remote temperatures and limits, it uses signed 11-bit values with
842 * LSB = 0.125 degree Celsius, left-justified in 16-bit registers. Some
868 if (val <= -128000) in temp_to_s8()
869 return -128; in temp_to_s8()
873 return (val - 500) / 1000; in temp_to_s8()
888 if (val <= -128000) in temp_to_s16()
893 return (val - 62) / 125 * 32; in temp_to_s16()
912 * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC.
916 if (data->flags & LM90_FLAG_ADT7461_EXT) in temp_from_u8_adt7461()
917 return (val - 64) * 1000; in temp_from_u8_adt7461()
923 if (data->flags & LM90_FLAG_ADT7461_EXT) in temp_from_u16_adt7461()
924 return (val - 0x4000) / 64 * 250; in temp_from_u16_adt7461()
930 if (data->flags & LM90_FLAG_ADT7461_EXT) { in temp_to_u8_adt7461()
931 if (val <= -64000) in temp_to_u8_adt7461()
946 if (data->flags & LM90_FLAG_ADT7461_EXT) { in temp_to_u16_adt7461()
947 if (val <= -64000) in temp_to_u16_adt7461()
966 return sprintf(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC)); in pec_show()
982 client->flags &= ~I2C_CLIENT_PEC; in pec_store()
985 client->flags |= I2C_CLIENT_PEC; in pec_store()
988 return -EINVAL; in pec_store()
998 s16 temp11 = data->temp11[index]; in lm90_get_temp11()
1001 if (data->kind == adt7461 || data->kind == tmp451) in lm90_get_temp11()
1003 else if (data->kind == max6646) in lm90_get_temp11()
1009 if (data->kind == lm99 && index <= 2) in lm90_get_temp11()
1027 struct i2c_client *client = data->client; in lm90_set_temp11()
1032 if (data->kind == lm99 && index <= 2) { in lm90_set_temp11()
1034 val = max(val, -128000l); in lm90_set_temp11()
1035 val -= 16000; in lm90_set_temp11()
1038 if (data->kind == adt7461 || data->kind == tmp451) in lm90_set_temp11()
1039 data->temp11[index] = temp_to_u16_adt7461(data, val); in lm90_set_temp11()
1040 else if (data->kind == max6646) in lm90_set_temp11()
1041 data->temp11[index] = temp_to_u8(val) << 8; in lm90_set_temp11()
1042 else if (data->flags & LM90_HAVE_REM_LIMIT_EXT) in lm90_set_temp11()
1043 data->temp11[index] = temp_to_s16(val); in lm90_set_temp11()
1045 data->temp11[index] = temp_to_s8(val) << 8; in lm90_set_temp11()
1048 err = i2c_smbus_write_byte_data(client, regp->high, in lm90_set_temp11()
1049 data->temp11[index] >> 8); in lm90_set_temp11()
1052 if (data->flags & LM90_HAVE_REM_LIMIT_EXT) in lm90_set_temp11()
1053 err = i2c_smbus_write_byte_data(client, regp->low, in lm90_set_temp11()
1054 data->temp11[index] & 0xff); in lm90_set_temp11()
1062 s8 temp8 = data->temp8[index]; in lm90_get_temp8()
1065 if (data->kind == adt7461 || data->kind == tmp451) in lm90_get_temp8()
1067 else if (data->kind == max6646) in lm90_get_temp8()
1073 if (data->kind == lm99 && index == 3) in lm90_get_temp8()
1091 struct i2c_client *client = data->client; in lm90_set_temp8()
1095 if (data->kind == lm99 && index == 3) { in lm90_set_temp8()
1097 val = max(val, -128000l); in lm90_set_temp8()
1098 val -= 16000; in lm90_set_temp8()
1101 if (data->kind == adt7461 || data->kind == tmp451) in lm90_set_temp8()
1102 data->temp8[index] = temp_to_u8_adt7461(data, val); in lm90_set_temp8()
1103 else if (data->kind == max6646) in lm90_set_temp8()
1104 data->temp8[index] = temp_to_u8(val); in lm90_set_temp8()
1106 data->temp8[index] = temp_to_s8(val); in lm90_set_temp8()
1109 err = i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]); in lm90_set_temp8()
1119 if (data->kind == adt7461 || data->kind == tmp451) in lm90_get_temphyst()
1120 temp = temp_from_u8_adt7461(data, data->temp8[index]); in lm90_get_temphyst()
1121 else if (data->kind == max6646) in lm90_get_temphyst()
1122 temp = temp_from_u8(data->temp8[index]); in lm90_get_temphyst()
1124 temp = temp_from_s8(data->temp8[index]); in lm90_get_temphyst()
1127 if (data->kind == lm99 && index == 3) in lm90_get_temphyst()
1130 return temp - temp_from_s8(data->temp_hyst); in lm90_get_temphyst()
1135 struct i2c_client *client = data->client; in lm90_set_temphyst()
1139 if (data->kind == adt7461 || data->kind == tmp451) in lm90_set_temphyst()
1140 temp = temp_from_u8_adt7461(data, data->temp8[LOCAL_CRIT]); in lm90_set_temphyst()
1141 else if (data->kind == max6646) in lm90_set_temphyst()
1142 temp = temp_from_u8(data->temp8[LOCAL_CRIT]); in lm90_set_temphyst()
1144 temp = temp_from_s8(data->temp8[LOCAL_CRIT]); in lm90_set_temphyst()
1147 val = max(val, -128000l); in lm90_set_temphyst()
1149 data->temp_hyst = hyst_to_reg(temp - val); in lm90_set_temphyst()
1151 data->temp_hyst); in lm90_set_temphyst()
1186 mutex_lock(&data->update_lock); in lm90_temp_read()
1188 mutex_unlock(&data->update_lock); in lm90_temp_read()
1197 *val = (data->alarms >> lm90_min_alarm_bits[channel]) & 1; in lm90_temp_read()
1200 *val = (data->alarms >> lm90_max_alarm_bits[channel]) & 1; in lm90_temp_read()
1203 *val = (data->alarms >> lm90_crit_alarm_bits[channel]) & 1; in lm90_temp_read()
1206 *val = (data->alarms >> lm90_emergency_alarm_bits[channel]) & 1; in lm90_temp_read()
1209 *val = (data->alarms >> lm90_fault_bits[channel]) & 1; in lm90_temp_read()
1243 return -EOPNOTSUPP; in lm90_temp_read()
1253 mutex_lock(&data->update_lock); in lm90_temp_write()
1293 err = -EOPNOTSUPP; in lm90_temp_write()
1297 mutex_unlock(&data->update_lock); in lm90_temp_write()
1333 mutex_lock(&data->update_lock); in lm90_chip_read()
1335 mutex_unlock(&data->update_lock); in lm90_chip_read()
1341 *val = data->update_interval; in lm90_chip_read()
1344 *val = data->alarms; in lm90_chip_read()
1347 return -EOPNOTSUPP; in lm90_chip_read()
1356 struct i2c_client *client = data->client; in lm90_chip_write()
1359 mutex_lock(&data->update_lock); in lm90_chip_write()
1371 err = -EOPNOTSUPP; in lm90_chip_write()
1375 mutex_unlock(&data->update_lock); in lm90_chip_write()
1401 return -EOPNOTSUPP; in lm90_read()
1414 return -EOPNOTSUPP; in lm90_write()
1431 /* Return 0 if detection is successful, -ENODEV otherwise */
1435 struct i2c_adapter *adapter = client->adapter; in lm90_detect()
1436 int address = client->addr; in lm90_detect()
1441 return -ENODEV; in lm90_detect()
1449 return -ENODEV; in lm90_detect()
1454 return -ENODEV; in lm90_detect()
1469 dev_info(&adapter->dev, in lm90_detect()
1472 dev_info(&adapter->dev, in lm90_detect()
1495 info->flags |= I2C_CLIENT_PEC; in lm90_detect()
1512 * We read MAX6659_REG_R_REMOTE_EMERG twice, and re-read in lm90_detect()
1526 return -ENODEV; in lm90_detect()
1538 * For this reason it will be mis-detected as MAX6657 if its in lm90_detect()
1645 dev_dbg(&adapter->dev, in lm90_detect()
1648 return -ENODEV; in lm90_detect()
1651 strlcpy(info->type, name, I2C_NAME_SIZE); in lm90_detect()
1659 struct i2c_client *client = data->client; in lm90_restore_conf()
1662 lm90_write_convrate(data, data->convrate_orig); in lm90_restore_conf()
1664 data->config_orig); in lm90_restore_conf()
1674 data->convrate_orig = convrate; in lm90_init_client()
1682 data->config_orig = config; in lm90_init_client()
1683 data->config = config; in lm90_init_client()
1688 if (data->kind == adt7461 || data->kind == tmp451) { in lm90_init_client()
1690 data->flags |= LM90_FLAG_ADT7461_EXT; in lm90_init_client()
1696 * to -64 degree) mode for the remote temperature sensor. in lm90_init_client()
1698 if (data->kind == max6680) in lm90_init_client()
1703 * 0 degrees to -64 degrees). Note that extended resolution is not in lm90_init_client()
1707 if (data->kind == max6654) in lm90_init_client()
1713 if (data->kind == max6696) in lm90_init_client()
1720 if (client->irq) in lm90_init_client()
1726 return devm_add_action_or_reset(&client->dev, lm90_restore_conf, data); in lm90_init_client()
1738 if (data->kind == max6696) { in lm90_is_tripped()
1751 dev_dbg(&client->dev, in lm90_is_tripped()
1755 dev_dbg(&client->dev, in lm90_is_tripped()
1758 dev_dbg(&client->dev, in lm90_is_tripped()
1762 dev_dbg(&client->dev, in lm90_is_tripped()
1765 dev_dbg(&client->dev, in lm90_is_tripped()
1769 hwmon_notify_event(data->hwmon_dev, hwmon_temp, in lm90_is_tripped()
1772 hwmon_notify_event(data->hwmon_dev, hwmon_temp, in lm90_is_tripped()
1775 hwmon_notify_event(data->hwmon_dev, hwmon_temp, in lm90_is_tripped()
1778 hwmon_notify_event(data->hwmon_dev, hwmon_temp, in lm90_is_tripped()
1781 hwmon_notify_event(data->hwmon_dev, hwmon_temp, in lm90_is_tripped()
1784 hwmon_notify_event(data->hwmon_dev, hwmon_temp, in lm90_is_tripped()
1820 struct device *dev = &client->dev; in lm90_probe()
1821 struct i2c_adapter *adapter = client->adapter; in lm90_probe()
1844 return -ENOMEM; in lm90_probe()
1846 data->client = client; in lm90_probe()
1848 mutex_init(&data->update_lock); in lm90_probe()
1851 if (client->dev.of_node) in lm90_probe()
1852 data->kind = (enum chips)of_device_get_match_data(&client->dev); in lm90_probe()
1854 data->kind = i2c_match_id(lm90_id, client)->driver_data; in lm90_probe()
1855 if (data->kind == adm1032) { in lm90_probe()
1857 client->flags &= ~I2C_CLIENT_PEC; in lm90_probe()
1862 * ALERT# output in lm90_probe()
1864 data->alert_alarms = lm90_params[data->kind].alert_alarms; in lm90_probe()
1867 data->flags = lm90_params[data->kind].flags; in lm90_probe()
1869 data->chip.ops = &lm90_ops; in lm90_probe()
1870 data->chip.info = data->info; in lm90_probe()
1872 data->info[0] = HWMON_CHANNEL_INFO(chip, in lm90_probe()
1874 data->info[1] = &data->temp_info; in lm90_probe()
1876 info = &data->temp_info; in lm90_probe()
1877 info->type = hwmon_temp; in lm90_probe()
1878 info->config = data->channel_config; in lm90_probe()
1880 data->channel_config[0] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in lm90_probe()
1883 data->channel_config[1] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in lm90_probe()
1887 if (data->flags & LM90_HAVE_OFFSET) in lm90_probe()
1888 data->channel_config[1] |= HWMON_T_OFFSET; in lm90_probe()
1890 if (data->flags & LM90_HAVE_EMERGENCY) { in lm90_probe()
1891 data->channel_config[0] |= HWMON_T_EMERGENCY | in lm90_probe()
1893 data->channel_config[1] |= HWMON_T_EMERGENCY | in lm90_probe()
1897 if (data->flags & LM90_HAVE_EMERGENCY_ALARM) { in lm90_probe()
1898 data->channel_config[0] |= HWMON_T_EMERGENCY_ALARM; in lm90_probe()
1899 data->channel_config[1] |= HWMON_T_EMERGENCY_ALARM; in lm90_probe()
1902 if (data->flags & LM90_HAVE_TEMP3) { in lm90_probe()
1903 data->channel_config[2] = HWMON_T_INPUT | in lm90_probe()
1912 data->reg_local_ext = lm90_params[data->kind].reg_local_ext; in lm90_probe()
1915 data->max_convrate = lm90_params[data->kind].max_convrate; in lm90_probe()
1928 if (client->flags & I2C_CLIENT_PEC) { in lm90_probe()
1937 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in lm90_probe()
1938 data, &data->chip, in lm90_probe()
1943 data->hwmon_dev = hwmon_dev; in lm90_probe()
1945 if (client->irq) { in lm90_probe()
1946 dev_dbg(dev, "IRQ: %d\n", client->irq); in lm90_probe()
1947 err = devm_request_threaded_irq(dev, client->irq, in lm90_probe()
1951 dev_err(dev, "cannot request IRQ %d\n", client->irq); in lm90_probe()
1969 * Disable ALERT# output, because these chips don't implement in lm90_alert()
1970 * SMBus alert correctly; they should only hold the alert line in lm90_alert()
1975 if ((data->flags & LM90_HAVE_BROKEN_ALERT) && in lm90_alert()
1976 (alarms & data->alert_alarms)) { in lm90_alert()
1977 dev_dbg(&client->dev, "Disabling ALERT#\n"); in lm90_alert()
1978 lm90_update_confreg(data, data->config | 0x80); in lm90_alert()
1981 dev_dbg(&client->dev, "Everything OK\n"); in lm90_alert()
1988 struct i2c_client *client = data->client; in lm90_suspend()
1990 if (client->irq) in lm90_suspend()
1991 disable_irq(client->irq); in lm90_suspend()
1999 struct i2c_client *client = data->client; in lm90_resume()
2001 if (client->irq) in lm90_resume()
2002 enable_irq(client->irq); in lm90_resume()
2017 .alert = lm90_alert,