// SPDX-License-Identifier: GPL-2.0-only /* * mlx90614.c - Support for Melexis MLX90614/MLX90615 contactless IR temperature sensor * * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net> * Copyright (c) 2015 Essensium NV * Copyright (c) 2015 Melexis * * Driver for the Melexis MLX90614/MLX90615 I2C 16-bit IR thermopile sensor * * MLX90614 - 17-bit ADC + MLX90302 DSP * MLX90615 - 16-bit ADC + MLX90325 DSP * * (7-bit I2C slave address 0x5a, 100KHz bus speed only!) * * To wake up from sleep mode, the SDA line must be held low while SCL is high * for at least 33ms. This is achieved with an extra GPIO that can be connected * directly to the SDA line. In normal operation, the GPIO is set as input and * will not interfere in I2C communication. While the GPIO is driven low, the * i2c adapter is locked since it cannot be used by other clients. The SCL line * always has a pull-up so we do not need an extra GPIO to drive it high. If * the "wakeup" GPIO is not given, power management will be disabled.
*/
/* Timings (in ms) */ #define MLX90614_TIMING_EEPROM 20 /* time for EEPROM write/erase to complete */ #define MLX90614_TIMING_WAKEUP 34 /* time to hold SDA low for wake-up */ #define MLX90614_TIMING_STARTUP 250 /* time before first data after wake-up */
#define MLX90615_TIMING_WAKEUP 22 /* time to hold SCL low for wake-up */
/* Magic constants */ #define MLX90614_CONST_OFFSET_DEC -13657 /* decimal part of the Kelvin offset */ #define MLX90614_CONST_OFFSET_REM 500000 /* remainder of offset (273.15*50) */ #define MLX90614_CONST_SCALE 20 /* Scale in milliKelvin (0.02 * 1000) */ #define MLX90614_CONST_FIR 0x7 /* Fixed value for FIR part of low pass filter */
struct mlx_chip_info { /* EEPROM offsets with 16-bit data, MSB first */ /* emissivity correction coefficient */
u8 op_eeprom_emissivity;
u8 op_eeprom_config1; /* RAM offsets with 16-bit data, MSB first */ /* ambient temperature */
u8 op_ram_ta; /* object 1 temperature */
u8 op_ram_tobj1; /* object 2 temperature */
u8 op_ram_tobj2;
u8 op_sleep; /* support for two input channels (MLX90614 only) */
u8 dual_channel;
u8 wakeup_delay_ms;
u16 emissivity_max;
u16 fir_config_mask;
u16 iir_config_mask; int iir_valid_offset;
u16 iir_values[8]; int iir_freqs[8][2];
};
struct mlx90614_data { struct i2c_client *client; struct mutex lock; /* for EEPROM access only */ struct gpio_desc *wakeup_gpio; /* NULL to disable sleep/wake-up */ conststruct mlx_chip_info *chip_info; /* Chip hardware details */ unsignedlong ready_timestamp; /* in jiffies */
};
/* * Erase an address and write word. * The mutex must be locked before calling.
*/ static s32 mlx90614_write_word(conststruct i2c_client *client, u8 command,
u16 value)
{ /* * Note: The mlx90614 requires a PEC on writing but does not send us a * valid PEC on reading. Hence, we cannot set I2C_CLIENT_PEC in * i2c_client.flags. As a workaround, we use i2c_smbus_xfer here.
*/ union i2c_smbus_data data;
s32 ret;
dev_dbg(&client->dev, "Writing 0x%x to address 0x%x", value, command);
data.word = value; /* actual write */
ret = i2c_smbus_xfer(client->adapter, client->addr,
client->flags | I2C_CLIENT_PEC,
I2C_SMBUS_WRITE, command,
I2C_SMBUS_WORD_DATA, &data);
msleep(MLX90614_TIMING_EEPROM);
return ret;
}
/* * Find the IIR value inside iir_values array and return its position * which is equivalent to the bit value in sensor register
*/ staticinline s32 mlx90614_iir_search(conststruct i2c_client *client, int value)
{ struct iio_dev *indio_dev = i2c_get_clientdata(client); struct mlx90614_data *data = iio_priv(indio_dev); conststruct mlx_chip_info *chip_info = data->chip_info; int i;
s32 ret;
for (i = chip_info->iir_valid_offset;
i < ARRAY_SIZE(chip_info->iir_values);
i++) { if (value == chip_info->iir_values[i]) break;
}
if (i == ARRAY_SIZE(chip_info->iir_values)) return -EINVAL;
/* * CONFIG register values must not be changed so * we must read them before we actually write * changes
*/
ret = i2c_smbus_read_word_data(client, chip_info->op_eeprom_config1); if (ret < 0) return ret;
/* Modify FIR on parts which have configurable FIR filter */ if (chip_info->fir_config_mask) {
ret &= ~chip_info->fir_config_mask;
ret |= field_prep(chip_info->fir_config_mask, MLX90614_CONST_FIR);
}
ret &= ~chip_info->iir_config_mask;
ret |= field_prep(chip_info->iir_config_mask, i);
#ifdef CONFIG_PM /* * If @startup is true, make sure MLX90614_TIMING_STARTUP ms have elapsed since * the last wake-up. This is normally only needed to get a valid temperature * reading. EEPROM access does not need such delay. * Return 0 on success, <0 on error.
*/ staticint mlx90614_power_get(struct mlx90614_data *data, bool startup)
{ unsignedlong now; int ret;
if (!data->wakeup_gpio) return 0;
ret = pm_runtime_resume_and_get(&data->client->dev); if (ret < 0) return ret;
if (startup) {
now = jiffies; if (time_before(now, data->ready_timestamp) &&
msleep_interruptible(jiffies_to_msecs(
data->ready_timestamp - now)) != 0) {
pm_runtime_put_autosuspend(&data->client->dev); return -EINTR;
}
}
return 0;
}
staticvoid mlx90614_power_put(struct mlx90614_data *data)
{ if (!data->wakeup_gpio) return;
/* * Quirk: the i2c controller may get confused right after the * wake-up signal has been sent. As a workaround, do a dummy read. * If the read fails, the controller will probably be reset so that * further reads will work.
*/
i2c_smbus_read_word_data(data->client, chip_info->op_eeprom_config1);
return 0;
}
/* Return wake-up GPIO or NULL if sleep functionality should be disabled. */ staticstruct gpio_desc *mlx90614_probe_wakeup(struct i2c_client *client)
{ struct gpio_desc *gpio;
if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WRITE_BYTE)) {
dev_info(&client->dev, "i2c adapter does not support SMBUS_WRITE_BYTE, sleep disabled"); return NULL;
}
if (data->wakeup_gpio) {
pm_runtime_disable(&client->dev); if (!pm_runtime_status_suspended(&client->dev))
mlx90614_sleep(data);
pm_runtime_set_suspended(&client->dev);
}
}
MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
MODULE_AUTHOR("Vianney le Clément de Saint-Marcq <vianney.leclement@essensium.com>");
MODULE_AUTHOR("Crt Mori <cmo@melexis.com>");
MODULE_DESCRIPTION("Melexis MLX90614 contactless IR temperature sensor driver");
MODULE_LICENSE("GPL");
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-04-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.