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# */
483 u16 alert_alarms; /* Which alarm bits trigger ALERT# */
505 return i2c_smbus_xfer(client->adapter, client->addr, in adm1032_write_byte()
506 client->flags & ~I2C_CLIENT_PEC, in adm1032_write_byte()
511 * It is assumed that client->update_lock is held (unless we are in
520 if (client->flags & I2C_CLIENT_PEC) { in lm90_read_reg()
538 * the one-shot conversion register, which we don't want to do in lm90_read16()
566 if (data->config != config) { in lm90_update_confreg()
569 err = i2c_smbus_write_byte_data(data->client, in lm90_update_confreg()
574 data->config = config; in lm90_update_confreg()
580 * client->update_lock must be held when calling this function (unless we are
582 * than channel 0 is selected. Also, calling code must make sure to re-select
585 * non-default remote channel.
591 if (data->kind == max6696) { in lm90_select_remote_channel()
592 u8 config = data->config & ~0x08; in lm90_select_remote_channel()
603 u8 config = data->config; in lm90_write_convrate()
607 if (data->flags & LM90_PAUSE_FOR_CONFIG) { in lm90_write_convrate()
614 err = i2c_smbus_write_byte_data(data->client, LM90_REG_W_CONVRATE, val); in lm90_write_convrate()
624 * client->update_lock must be held when calling this function (unless we are
638 i < data->max_convrate; i++, update_interval >>= 1) in lm90_set_convrate()
643 data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64); in lm90_set_convrate()
650 struct i2c_client *client = data->client; in lm90_update_limits()
656 data->temp8[LOCAL_CRIT] = val; in lm90_update_limits()
661 data->temp8[REMOTE_CRIT] = val; in lm90_update_limits()
666 data->temp_hyst = val; in lm90_update_limits()
671 data->temp11[REMOTE_LOW] = val << 8; in lm90_update_limits()
673 if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { in lm90_update_limits()
677 data->temp11[REMOTE_LOW] |= val; in lm90_update_limits()
683 data->temp11[REMOTE_HIGH] = val << 8; in lm90_update_limits()
685 if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { in lm90_update_limits()
689 data->temp11[REMOTE_HIGH] |= val; in lm90_update_limits()
692 if (data->flags & LM90_HAVE_OFFSET) { in lm90_update_limits()
697 data->temp11[REMOTE_OFFSET] = val; in lm90_update_limits()
700 if (data->flags & LM90_HAVE_EMERGENCY) { in lm90_update_limits()
704 data->temp8[LOCAL_EMERG] = val; in lm90_update_limits()
709 data->temp8[REMOTE_EMERG] = val; in lm90_update_limits()
712 if (data->kind == max6696) { in lm90_update_limits()
720 data->temp8[REMOTE2_CRIT] = val; in lm90_update_limits()
725 data->temp8[REMOTE2_EMERG] = val; in lm90_update_limits()
730 data->temp11[REMOTE2_LOW] = val << 8; in lm90_update_limits()
735 data->temp11[REMOTE2_HIGH] = val << 8; in lm90_update_limits()
746 struct i2c_client *client = data->client; in lm90_update_device()
750 if (!data->valid) { in lm90_update_device()
756 next_update = data->last_updated + in lm90_update_device()
757 msecs_to_jiffies(data->update_interval); in lm90_update_device()
758 if (time_after(jiffies, next_update) || !data->valid) { in lm90_update_device()
759 dev_dbg(&client->dev, "Updating lm90 data.\n"); in lm90_update_device()
761 data->valid = false; in lm90_update_device()
766 data->temp8[LOCAL_LOW] = val; in lm90_update_device()
771 data->temp8[LOCAL_HIGH] = val; in lm90_update_device()
773 if (data->reg_local_ext) { in lm90_update_device()
775 data->reg_local_ext); in lm90_update_device()
778 data->temp11[LOCAL_TEMP] = val; in lm90_update_device()
783 data->temp11[LOCAL_TEMP] = val << 8; in lm90_update_device()
789 data->temp11[REMOTE_TEMP] = val; in lm90_update_device()
794 data->alarms = val; /* lower 8 bit of alarms */ in lm90_update_device()
796 if (data->kind == max6696) { in lm90_update_device()
807 data->temp11[REMOTE2_TEMP] = val; in lm90_update_device()
814 data->alarms |= val << 8; in lm90_update_device()
818 * Re-enable ALERT# output if it was originally enabled and in lm90_update_device()
821 if (!(data->config_orig & 0x80) && in lm90_update_device()
822 !(data->alarms & data->alert_alarms)) { in lm90_update_device()
823 if (data->config & 0x80) { in lm90_update_device()
824 dev_dbg(&client->dev, "Re-enabling ALERT#\n"); in lm90_update_device()
825 lm90_update_confreg(data, data->config & ~0x80); in lm90_update_device()
829 data->last_updated = jiffies; in lm90_update_device()
830 data->valid = true; in lm90_update_device()
839 * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius.
840 * For remote temperatures and limits, it uses signed 11-bit values with
841 * LSB = 0.125 degree Celsius, left-justified in 16-bit registers. Some
867 if (val <= -128000) in temp_to_s8()
868 return -128; in temp_to_s8()
872 return (val - 500) / 1000; in temp_to_s8()
887 if (val <= -128000) in temp_to_s16()
892 return (val - 62) / 125 * 32; in temp_to_s16()
911 * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC.
915 if (data->flags & LM90_FLAG_ADT7461_EXT) in temp_from_u8_adt7461()
916 return (val - 64) * 1000; in temp_from_u8_adt7461()
922 if (data->flags & LM90_FLAG_ADT7461_EXT) in temp_from_u16_adt7461()
923 return (val - 0x4000) / 64 * 250; in temp_from_u16_adt7461()
929 if (data->flags & LM90_FLAG_ADT7461_EXT) { in temp_to_u8_adt7461()
930 if (val <= -64000) in temp_to_u8_adt7461()
945 if (data->flags & LM90_FLAG_ADT7461_EXT) { in temp_to_u16_adt7461()
946 if (val <= -64000) in temp_to_u16_adt7461()
965 return sprintf(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC)); in pec_show()
981 client->flags &= ~I2C_CLIENT_PEC; in pec_store()
984 client->flags |= I2C_CLIENT_PEC; in pec_store()
987 return -EINVAL; in pec_store()
997 s16 temp11 = data->temp11[index]; in lm90_get_temp11()
1000 if (data->kind == adt7461 || data->kind == tmp451) in lm90_get_temp11()
1002 else if (data->kind == max6646) in lm90_get_temp11()
1008 if (data->kind == lm99 && index <= 2) in lm90_get_temp11()
1026 struct i2c_client *client = data->client; in lm90_set_temp11()
1031 if (data->kind == lm99 && index <= 2) in lm90_set_temp11()
1032 val -= 16000; in lm90_set_temp11()
1034 if (data->kind == adt7461 || data->kind == tmp451) in lm90_set_temp11()
1035 data->temp11[index] = temp_to_u16_adt7461(data, val); in lm90_set_temp11()
1036 else if (data->kind == max6646) in lm90_set_temp11()
1037 data->temp11[index] = temp_to_u8(val) << 8; in lm90_set_temp11()
1038 else if (data->flags & LM90_HAVE_REM_LIMIT_EXT) in lm90_set_temp11()
1039 data->temp11[index] = temp_to_s16(val); in lm90_set_temp11()
1041 data->temp11[index] = temp_to_s8(val) << 8; in lm90_set_temp11()
1044 err = i2c_smbus_write_byte_data(client, regp->high, in lm90_set_temp11()
1045 data->temp11[index] >> 8); in lm90_set_temp11()
1048 if (data->flags & LM90_HAVE_REM_LIMIT_EXT) in lm90_set_temp11()
1049 err = i2c_smbus_write_byte_data(client, regp->low, in lm90_set_temp11()
1050 data->temp11[index] & 0xff); in lm90_set_temp11()
1058 s8 temp8 = data->temp8[index]; in lm90_get_temp8()
1061 if (data->kind == adt7461 || data->kind == tmp451) in lm90_get_temp8()
1063 else if (data->kind == max6646) in lm90_get_temp8()
1069 if (data->kind == lm99 && index == 3) in lm90_get_temp8()
1087 struct i2c_client *client = data->client; in lm90_set_temp8()
1091 if (data->kind == lm99 && index == 3) in lm90_set_temp8()
1092 val -= 16000; in lm90_set_temp8()
1094 if (data->kind == adt7461 || data->kind == tmp451) in lm90_set_temp8()
1095 data->temp8[index] = temp_to_u8_adt7461(data, val); in lm90_set_temp8()
1096 else if (data->kind == max6646) in lm90_set_temp8()
1097 data->temp8[index] = temp_to_u8(val); in lm90_set_temp8()
1099 data->temp8[index] = temp_to_s8(val); in lm90_set_temp8()
1102 err = i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]); in lm90_set_temp8()
1112 if (data->kind == adt7461 || data->kind == tmp451) in lm90_get_temphyst()
1113 temp = temp_from_u8_adt7461(data, data->temp8[index]); in lm90_get_temphyst()
1114 else if (data->kind == max6646) in lm90_get_temphyst()
1115 temp = temp_from_u8(data->temp8[index]); in lm90_get_temphyst()
1117 temp = temp_from_s8(data->temp8[index]); in lm90_get_temphyst()
1120 if (data->kind == lm99 && index == 3) in lm90_get_temphyst()
1123 return temp - temp_from_s8(data->temp_hyst); in lm90_get_temphyst()
1128 struct i2c_client *client = data->client; in lm90_set_temphyst()
1132 if (data->kind == adt7461 || data->kind == tmp451) in lm90_set_temphyst()
1133 temp = temp_from_u8_adt7461(data, data->temp8[LOCAL_CRIT]); in lm90_set_temphyst()
1134 else if (data->kind == max6646) in lm90_set_temphyst()
1135 temp = temp_from_u8(data->temp8[LOCAL_CRIT]); in lm90_set_temphyst()
1137 temp = temp_from_s8(data->temp8[LOCAL_CRIT]); in lm90_set_temphyst()
1139 data->temp_hyst = hyst_to_reg(temp - val); in lm90_set_temphyst()
1141 data->temp_hyst); in lm90_set_temphyst()
1176 mutex_lock(&data->update_lock); in lm90_temp_read()
1178 mutex_unlock(&data->update_lock); in lm90_temp_read()
1187 *val = (data->alarms >> lm90_min_alarm_bits[channel]) & 1; in lm90_temp_read()
1190 *val = (data->alarms >> lm90_max_alarm_bits[channel]) & 1; in lm90_temp_read()
1193 *val = (data->alarms >> lm90_crit_alarm_bits[channel]) & 1; in lm90_temp_read()
1196 *val = (data->alarms >> lm90_emergency_alarm_bits[channel]) & 1; in lm90_temp_read()
1199 *val = (data->alarms >> lm90_fault_bits[channel]) & 1; in lm90_temp_read()
1233 return -EOPNOTSUPP; in lm90_temp_read()
1243 mutex_lock(&data->update_lock); in lm90_temp_write()
1283 err = -EOPNOTSUPP; in lm90_temp_write()
1287 mutex_unlock(&data->update_lock); in lm90_temp_write()
1323 mutex_lock(&data->update_lock); in lm90_chip_read()
1325 mutex_unlock(&data->update_lock); in lm90_chip_read()
1331 *val = data->update_interval; in lm90_chip_read()
1334 *val = data->alarms; in lm90_chip_read()
1337 return -EOPNOTSUPP; in lm90_chip_read()
1346 struct i2c_client *client = data->client; in lm90_chip_write()
1349 mutex_lock(&data->update_lock); in lm90_chip_write()
1361 err = -EOPNOTSUPP; in lm90_chip_write()
1365 mutex_unlock(&data->update_lock); in lm90_chip_write()
1391 return -EOPNOTSUPP; in lm90_read()
1404 return -EOPNOTSUPP; in lm90_write()
1421 /* Return 0 if detection is successful, -ENODEV otherwise */
1425 struct i2c_adapter *adapter = client->adapter; in lm90_detect()
1426 int address = client->addr; in lm90_detect()
1431 return -ENODEV; in lm90_detect()
1439 return -ENODEV; in lm90_detect()
1444 return -ENODEV; in lm90_detect()
1459 dev_info(&adapter->dev, in lm90_detect()
1462 dev_info(&adapter->dev, in lm90_detect()
1485 info->flags |= I2C_CLIENT_PEC; in lm90_detect()
1502 * We read MAX6659_REG_R_REMOTE_EMERG twice, and re-read in lm90_detect()
1516 return -ENODEV; in lm90_detect()
1528 * For this reason it will be mis-detected as MAX6657 if its in lm90_detect()
1635 dev_dbg(&adapter->dev, in lm90_detect()
1638 return -ENODEV; in lm90_detect()
1641 strlcpy(info->type, name, I2C_NAME_SIZE); in lm90_detect()
1649 struct i2c_client *client = data->client; in lm90_restore_conf()
1652 lm90_write_convrate(data, data->convrate_orig); in lm90_restore_conf()
1654 data->config_orig); in lm90_restore_conf()
1664 data->convrate_orig = convrate; in lm90_init_client()
1672 data->config_orig = config; in lm90_init_client()
1673 data->config = config; in lm90_init_client()
1678 if (data->kind == adt7461 || data->kind == tmp451) { in lm90_init_client()
1680 data->flags |= LM90_FLAG_ADT7461_EXT; in lm90_init_client()
1686 * to -64 degree) mode for the remote temperature sensor. in lm90_init_client()
1688 if (data->kind == max6680) in lm90_init_client()
1693 * 0 degrees to -64 degrees). Note that extended resolution is not in lm90_init_client()
1697 if (data->kind == max6654) in lm90_init_client()
1703 if (data->kind == max6696) in lm90_init_client()
1709 return devm_add_action_or_reset(&client->dev, lm90_restore_conf, data); in lm90_init_client()
1721 if (data->kind == max6696) { in lm90_is_tripped()
1734 dev_warn(&client->dev, in lm90_is_tripped()
1738 dev_warn(&client->dev, in lm90_is_tripped()
1741 dev_warn(&client->dev, in lm90_is_tripped()
1745 dev_warn(&client->dev, in lm90_is_tripped()
1748 dev_warn(&client->dev, in lm90_is_tripped()
1784 struct device *dev = &client->dev; in lm90_probe()
1785 struct i2c_adapter *adapter = client->adapter; in lm90_probe()
1808 return -ENOMEM; in lm90_probe()
1810 data->client = client; in lm90_probe()
1812 mutex_init(&data->update_lock); in lm90_probe()
1815 if (client->dev.of_node) in lm90_probe()
1816 data->kind = (enum chips)of_device_get_match_data(&client->dev); in lm90_probe()
1818 data->kind = i2c_match_id(lm90_id, client)->driver_data; in lm90_probe()
1819 if (data->kind == adm1032) { in lm90_probe()
1821 client->flags &= ~I2C_CLIENT_PEC; in lm90_probe()
1826 * ALERT# output in lm90_probe()
1828 data->alert_alarms = lm90_params[data->kind].alert_alarms; in lm90_probe()
1831 data->flags = lm90_params[data->kind].flags; in lm90_probe()
1833 data->chip.ops = &lm90_ops; in lm90_probe()
1834 data->chip.info = data->info; in lm90_probe()
1836 data->info[0] = HWMON_CHANNEL_INFO(chip, in lm90_probe()
1838 data->info[1] = &data->temp_info; in lm90_probe()
1840 info = &data->temp_info; in lm90_probe()
1841 info->type = hwmon_temp; in lm90_probe()
1842 info->config = data->channel_config; in lm90_probe()
1844 data->channel_config[0] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in lm90_probe()
1847 data->channel_config[1] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | in lm90_probe()
1851 if (data->flags & LM90_HAVE_OFFSET) in lm90_probe()
1852 data->channel_config[1] |= HWMON_T_OFFSET; in lm90_probe()
1854 if (data->flags & LM90_HAVE_EMERGENCY) { in lm90_probe()
1855 data->channel_config[0] |= HWMON_T_EMERGENCY | in lm90_probe()
1857 data->channel_config[1] |= HWMON_T_EMERGENCY | in lm90_probe()
1861 if (data->flags & LM90_HAVE_EMERGENCY_ALARM) { in lm90_probe()
1862 data->channel_config[0] |= HWMON_T_EMERGENCY_ALARM; in lm90_probe()
1863 data->channel_config[1] |= HWMON_T_EMERGENCY_ALARM; in lm90_probe()
1866 if (data->flags & LM90_HAVE_TEMP3) { in lm90_probe()
1867 data->channel_config[2] = HWMON_T_INPUT | in lm90_probe()
1876 data->reg_local_ext = lm90_params[data->kind].reg_local_ext; in lm90_probe()
1879 data->max_convrate = lm90_params[data->kind].max_convrate; in lm90_probe()
1892 if (client->flags & I2C_CLIENT_PEC) { in lm90_probe()
1901 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in lm90_probe()
1902 data, &data->chip, in lm90_probe()
1907 if (client->irq) { in lm90_probe()
1908 dev_dbg(dev, "IRQ: %d\n", client->irq); in lm90_probe()
1909 err = devm_request_threaded_irq(dev, client->irq, in lm90_probe()
1914 dev_err(dev, "cannot request IRQ %d\n", client->irq); in lm90_probe()
1932 * Disable ALERT# output, because these chips don't implement in lm90_alert()
1933 * SMBus alert correctly; they should only hold the alert line in lm90_alert()
1938 if ((data->flags & LM90_HAVE_BROKEN_ALERT) && in lm90_alert()
1939 (alarms & data->alert_alarms)) { in lm90_alert()
1940 dev_dbg(&client->dev, "Disabling ALERT#\n"); in lm90_alert()
1941 lm90_update_confreg(data, data->config | 0x80); in lm90_alert()
1944 dev_info(&client->dev, "Everything OK\n"); in lm90_alert()
1955 .alert = lm90_alert,