1 // SPDX-License-Identifier: GPL-2.0-only
3 * mlx90614.c - Support for Melexis MLX90614/MLX90615 contactless IR temperature sensor
5 * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
6 * Copyright (c) 2015 Essensium NV
7 * Copyright (c) 2015 Melexis
9 * Driver for the Melexis MLX90614/MLX90615 I2C 16-bit IR thermopile sensor
11 * MLX90614 - 17-bit ADC + MLX90302 DSP
12 * MLX90615 - 16-bit ADC + MLX90325 DSP
14 * (7-bit I2C slave address 0x5a, 100KHz bus speed only!)
16 * To wake up from sleep mode, the SDA line must be held low while SCL is high
17 * for at least 33ms. This is achieved with an extra GPIO that can be connected
18 * directly to the SDA line. In normal operation, the GPIO is set as input and
19 * will not interfere in I2C communication. While the GPIO is driven low, the
20 * i2c adapter is locked since it cannot be used by other clients. The SCL line
21 * always has a pull-up so we do not need an extra GPIO to drive it high. If
22 * the "wakeup" GPIO is not given, power management will be disabled.
25 #include <linux/delay.h>
26 #include <linux/err.h>
27 #include <linux/gpio/consumer.h>
28 #include <linux/i2c.h>
29 #include <linux/jiffies.h>
30 #include <linux/mod_devicetable.h>
31 #include <linux/module.h>
32 #include <linux/pm_runtime.h>
34 #include <linux/iio/iio.h>
35 #include <linux/iio/sysfs.h>
37 #define MLX90614_OP_RAM 0x00
38 #define MLX90614_OP_EEPROM 0x20
39 #define MLX90614_OP_SLEEP 0xff
41 #define MLX90615_OP_EEPROM 0x10
42 #define MLX90615_OP_RAM 0x20
43 #define MLX90615_OP_SLEEP 0xc6
45 /* Control bits in configuration register */
46 #define MLX90614_CONFIG_IIR_SHIFT 0 /* IIR coefficient */
47 #define MLX90614_CONFIG_IIR_MASK (0x7 << MLX90614_CONFIG_IIR_SHIFT)
48 #define MLX90614_CONFIG_DUAL_SHIFT 6 /* single (0) or dual (1) IR sensor */
49 #define MLX90614_CONFIG_DUAL_MASK (1 << MLX90614_CONFIG_DUAL_SHIFT)
50 #define MLX90614_CONFIG_FIR_SHIFT 8 /* FIR coefficient */
51 #define MLX90614_CONFIG_FIR_MASK (0x7 << MLX90614_CONFIG_FIR_SHIFT)
53 #define MLX90615_CONFIG_IIR_SHIFT 12 /* IIR coefficient */
54 #define MLX90615_CONFIG_IIR_MASK (0x7 << MLX90615_CONFIG_IIR_SHIFT)
57 #define MLX90614_TIMING_EEPROM 20 /* time for EEPROM write/erase to complete */
58 #define MLX90614_TIMING_WAKEUP 34 /* time to hold SDA low for wake-up */
59 #define MLX90614_TIMING_STARTUP 250 /* time before first data after wake-up */
61 #define MLX90615_TIMING_WAKEUP 22 /* time to hold SCL low for wake-up */
63 #define MLX90614_AUTOSLEEP_DELAY 5000 /* default autosleep delay */
66 #define MLX90614_CONST_OFFSET_DEC -13657 /* decimal part of the Kelvin offset */
67 #define MLX90614_CONST_OFFSET_REM 500000 /* remainder of offset (273.15*50) */
68 #define MLX90614_CONST_SCALE 20 /* Scale in milliKelvin (0.02 * 1000) */
69 #define MLX90614_CONST_FIR 0x7 /* Fixed value for FIR part of low pass filter */
71 /* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */
72 #define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))
73 #define field_prep(_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))
75 struct mlx_chip_info {
76 /* EEPROM offsets with 16-bit data, MSB first */
77 /* emissivity correction coefficient */
78 u8 op_eeprom_emissivity;
80 /* RAM offsets with 16-bit data, MSB first */
81 /* ambient temperature */
83 /* object 1 temperature */
85 /* object 2 temperature */
88 /* support for two input channels (MLX90614 only) */
99 struct mlx90614_data {
100 struct i2c_client *client;
101 struct mutex lock; /* for EEPROM access only */
102 struct gpio_desc *wakeup_gpio; /* NULL to disable sleep/wake-up */
103 const struct mlx_chip_info *chip_info; /* Chip hardware details */
104 unsigned long ready_timestamp; /* in jiffies */
108 * Erase an address and write word.
109 * The mutex must be locked before calling.
111 static s32 mlx90614_write_word(const struct i2c_client *client, u8 command,
115 * Note: The mlx90614 requires a PEC on writing but does not send us a
116 * valid PEC on reading. Hence, we cannot set I2C_CLIENT_PEC in
117 * i2c_client.flags. As a workaround, we use i2c_smbus_xfer here.
119 union i2c_smbus_data data;
122 dev_dbg(&client->dev, "Writing 0x%x to address 0x%x", value, command);
124 data.word = 0x0000; /* erase command */
125 ret = i2c_smbus_xfer(client->adapter, client->addr,
126 client->flags | I2C_CLIENT_PEC,
127 I2C_SMBUS_WRITE, command,
128 I2C_SMBUS_WORD_DATA, &data);
132 msleep(MLX90614_TIMING_EEPROM);
134 data.word = value; /* actual write */
135 ret = i2c_smbus_xfer(client->adapter, client->addr,
136 client->flags | I2C_CLIENT_PEC,
137 I2C_SMBUS_WRITE, command,
138 I2C_SMBUS_WORD_DATA, &data);
140 msleep(MLX90614_TIMING_EEPROM);
146 * Find the IIR value inside iir_values array and return its position
147 * which is equivalent to the bit value in sensor register
149 static inline s32 mlx90614_iir_search(const struct i2c_client *client,
152 struct iio_dev *indio_dev = i2c_get_clientdata(client);
153 struct mlx90614_data *data = iio_priv(indio_dev);
154 const struct mlx_chip_info *chip_info = data->chip_info;
158 for (i = chip_info->iir_valid_offset;
159 i < ARRAY_SIZE(chip_info->iir_values);
161 if (value == chip_info->iir_values[i])
165 if (i == ARRAY_SIZE(chip_info->iir_values))
169 * CONFIG register values must not be changed so
170 * we must read them before we actually write
173 ret = i2c_smbus_read_word_data(client, chip_info->op_eeprom_config1);
177 /* Modify FIR on parts which have configurable FIR filter */
178 if (chip_info->fir_config_mask) {
179 ret &= ~chip_info->fir_config_mask;
180 ret |= field_prep(chip_info->fir_config_mask, MLX90614_CONST_FIR);
183 ret &= ~chip_info->iir_config_mask;
184 ret |= field_prep(chip_info->iir_config_mask, i);
186 /* Write changed values */
187 ret = mlx90614_write_word(client, chip_info->op_eeprom_config1, ret);
193 * If @startup is true, make sure MLX90614_TIMING_STARTUP ms have elapsed since
194 * the last wake-up. This is normally only needed to get a valid temperature
195 * reading. EEPROM access does not need such delay.
196 * Return 0 on success, <0 on error.
198 static int mlx90614_power_get(struct mlx90614_data *data, bool startup)
203 if (!data->wakeup_gpio)
206 ret = pm_runtime_resume_and_get(&data->client->dev);
212 if (time_before(now, data->ready_timestamp) &&
213 msleep_interruptible(jiffies_to_msecs(
214 data->ready_timestamp - now)) != 0) {
215 pm_runtime_put_autosuspend(&data->client->dev);
223 static void mlx90614_power_put(struct mlx90614_data *data)
225 if (!data->wakeup_gpio)
228 pm_runtime_mark_last_busy(&data->client->dev);
229 pm_runtime_put_autosuspend(&data->client->dev);
232 static inline int mlx90614_power_get(struct mlx90614_data *data, bool startup)
237 static inline void mlx90614_power_put(struct mlx90614_data *data)
242 static int mlx90614_read_raw(struct iio_dev *indio_dev,
243 struct iio_chan_spec const *channel, int *val,
244 int *val2, long mask)
246 struct mlx90614_data *data = iio_priv(indio_dev);
247 const struct mlx_chip_info *chip_info = data->chip_info;
252 case IIO_CHAN_INFO_RAW: /* 0.02K / LSB */
253 switch (channel->channel2) {
254 case IIO_MOD_TEMP_AMBIENT:
255 cmd = chip_info->op_ram_ta;
257 case IIO_MOD_TEMP_OBJECT:
258 if (chip_info->dual_channel && channel->channel)
261 switch (channel->channel) {
263 cmd = chip_info->op_ram_tobj1;
266 cmd = chip_info->op_ram_tobj2;
276 ret = mlx90614_power_get(data, true);
279 ret = i2c_smbus_read_word_data(data->client, cmd);
280 mlx90614_power_put(data);
285 /* MSB is an error flag */
291 case IIO_CHAN_INFO_OFFSET:
292 *val = MLX90614_CONST_OFFSET_DEC;
293 *val2 = MLX90614_CONST_OFFSET_REM;
294 return IIO_VAL_INT_PLUS_MICRO;
295 case IIO_CHAN_INFO_SCALE:
296 *val = MLX90614_CONST_SCALE;
298 case IIO_CHAN_INFO_CALIBEMISSIVITY: /* 1/emissivity_max / LSB */
299 ret = mlx90614_power_get(data, false);
303 mutex_lock(&data->lock);
304 ret = i2c_smbus_read_word_data(data->client,
305 chip_info->op_eeprom_emissivity);
306 mutex_unlock(&data->lock);
307 mlx90614_power_put(data);
312 if (ret == chip_info->emissivity_max) {
317 *val2 = ret * NSEC_PER_SEC / chip_info->emissivity_max;
319 return IIO_VAL_INT_PLUS_NANO;
320 /* IIR setting with FIR=1024 (MLX90614) or FIR=65536 (MLX90615) */
321 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
322 ret = mlx90614_power_get(data, false);
326 mutex_lock(&data->lock);
327 ret = i2c_smbus_read_word_data(data->client,
328 chip_info->op_eeprom_config1);
329 mutex_unlock(&data->lock);
330 mlx90614_power_put(data);
335 idx = field_get(chip_info->iir_config_mask, ret) -
336 chip_info->iir_valid_offset;
338 *val = chip_info->iir_values[idx] / 100;
339 *val2 = (chip_info->iir_values[idx] % 100) * 10000;
340 return IIO_VAL_INT_PLUS_MICRO;
346 static int mlx90614_write_raw(struct iio_dev *indio_dev,
347 struct iio_chan_spec const *channel, int val,
350 struct mlx90614_data *data = iio_priv(indio_dev);
351 const struct mlx_chip_info *chip_info = data->chip_info;
355 case IIO_CHAN_INFO_CALIBEMISSIVITY: /* 1/emissivity_max / LSB */
356 if (val < 0 || val2 < 0 || val > 1 || (val == 1 && val2 != 0))
358 val = val * chip_info->emissivity_max +
359 val2 * chip_info->emissivity_max / NSEC_PER_SEC;
361 ret = mlx90614_power_get(data, false);
365 mutex_lock(&data->lock);
366 ret = mlx90614_write_word(data->client,
367 chip_info->op_eeprom_emissivity, val);
368 mutex_unlock(&data->lock);
369 mlx90614_power_put(data);
372 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: /* IIR Filter setting */
373 if (val < 0 || val2 < 0)
376 ret = mlx90614_power_get(data, false);
380 mutex_lock(&data->lock);
381 ret = mlx90614_iir_search(data->client,
382 val * 100 + val2 / 10000);
383 mutex_unlock(&data->lock);
384 mlx90614_power_put(data);
392 static int mlx90614_write_raw_get_fmt(struct iio_dev *indio_dev,
393 struct iio_chan_spec const *channel,
397 case IIO_CHAN_INFO_CALIBEMISSIVITY:
398 return IIO_VAL_INT_PLUS_NANO;
399 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
400 return IIO_VAL_INT_PLUS_MICRO;
406 static int mlx90614_read_avail(struct iio_dev *indio_dev,
407 struct iio_chan_spec const *chan,
408 const int **vals, int *type, int *length,
411 struct mlx90614_data *data = iio_priv(indio_dev);
412 const struct mlx_chip_info *chip_info = data->chip_info;
415 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
416 *vals = (int *)chip_info->iir_freqs;
417 *type = IIO_VAL_INT_PLUS_MICRO;
418 *length = 2 * (ARRAY_SIZE(chip_info->iir_freqs) -
419 chip_info->iir_valid_offset);
420 return IIO_AVAIL_LIST;
426 static const struct iio_chan_spec mlx90614_channels[] = {
430 .channel2 = IIO_MOD_TEMP_AMBIENT,
431 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
432 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
433 BIT(IIO_CHAN_INFO_SCALE),
438 .channel2 = IIO_MOD_TEMP_OBJECT,
439 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
440 BIT(IIO_CHAN_INFO_CALIBEMISSIVITY) |
441 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),
442 .info_mask_separate_available =
443 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),
444 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
445 BIT(IIO_CHAN_INFO_SCALE),
452 .channel2 = IIO_MOD_TEMP_OBJECT,
453 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
454 BIT(IIO_CHAN_INFO_CALIBEMISSIVITY) |
455 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),
456 .info_mask_separate_available =
457 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),
458 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
459 BIT(IIO_CHAN_INFO_SCALE),
463 static const struct iio_info mlx90614_info = {
464 .read_raw = mlx90614_read_raw,
465 .write_raw = mlx90614_write_raw,
466 .write_raw_get_fmt = mlx90614_write_raw_get_fmt,
467 .read_avail = mlx90614_read_avail,
471 static int mlx90614_sleep(struct mlx90614_data *data)
473 const struct mlx_chip_info *chip_info = data->chip_info;
476 if (!data->wakeup_gpio) {
477 dev_dbg(&data->client->dev, "Sleep disabled");
481 dev_dbg(&data->client->dev, "Requesting sleep");
483 mutex_lock(&data->lock);
484 ret = i2c_smbus_xfer(data->client->adapter, data->client->addr,
485 data->client->flags | I2C_CLIENT_PEC,
486 I2C_SMBUS_WRITE, chip_info->op_sleep,
487 I2C_SMBUS_BYTE, NULL);
488 mutex_unlock(&data->lock);
493 static int mlx90614_wakeup(struct mlx90614_data *data)
495 const struct mlx_chip_info *chip_info = data->chip_info;
497 if (!data->wakeup_gpio) {
498 dev_dbg(&data->client->dev, "Wake-up disabled");
502 dev_dbg(&data->client->dev, "Requesting wake-up");
504 i2c_lock_bus(data->client->adapter, I2C_LOCK_ROOT_ADAPTER);
505 gpiod_direction_output(data->wakeup_gpio, 0);
506 msleep(chip_info->wakeup_delay_ms);
507 gpiod_direction_input(data->wakeup_gpio);
508 i2c_unlock_bus(data->client->adapter, I2C_LOCK_ROOT_ADAPTER);
510 data->ready_timestamp = jiffies +
511 msecs_to_jiffies(MLX90614_TIMING_STARTUP);
514 * Quirk: the i2c controller may get confused right after the
515 * wake-up signal has been sent. As a workaround, do a dummy read.
516 * If the read fails, the controller will probably be reset so that
517 * further reads will work.
519 i2c_smbus_read_word_data(data->client, chip_info->op_eeprom_config1);
524 /* Return wake-up GPIO or NULL if sleep functionality should be disabled. */
525 static struct gpio_desc *mlx90614_probe_wakeup(struct i2c_client *client)
527 struct gpio_desc *gpio;
529 if (!i2c_check_functionality(client->adapter,
530 I2C_FUNC_SMBUS_WRITE_BYTE)) {
531 dev_info(&client->dev,
532 "i2c adapter does not support SMBUS_WRITE_BYTE, sleep disabled");
536 gpio = devm_gpiod_get_optional(&client->dev, "wakeup", GPIOD_IN);
539 dev_warn(&client->dev,
540 "gpio acquisition failed with error %ld, sleep disabled",
544 dev_info(&client->dev,
545 "wakeup-gpio not found, sleep disabled");
551 static inline int mlx90614_sleep(struct mlx90614_data *data)
555 static inline int mlx90614_wakeup(struct mlx90614_data *data)
559 static inline struct gpio_desc *mlx90614_probe_wakeup(struct i2c_client *client)
565 /* Return 0 for single sensor, 1 for dual sensor, <0 on error. */
566 static int mlx90614_probe_num_ir_sensors(struct i2c_client *client)
568 struct iio_dev *indio_dev = i2c_get_clientdata(client);
569 struct mlx90614_data *data = iio_priv(indio_dev);
570 const struct mlx_chip_info *chip_info = data->chip_info;
573 if (chip_info->dual_channel)
576 ret = i2c_smbus_read_word_data(client, chip_info->op_eeprom_config1);
581 return (ret & MLX90614_CONFIG_DUAL_MASK) ? 1 : 0;
584 static int mlx90614_probe(struct i2c_client *client)
586 const struct i2c_device_id *id = i2c_client_get_device_id(client);
587 struct iio_dev *indio_dev;
588 struct mlx90614_data *data;
591 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
594 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
598 data = iio_priv(indio_dev);
599 i2c_set_clientdata(client, indio_dev);
600 data->client = client;
601 mutex_init(&data->lock);
602 data->wakeup_gpio = mlx90614_probe_wakeup(client);
603 data->chip_info = device_get_match_data(&client->dev);
605 mlx90614_wakeup(data);
607 indio_dev->name = id->name;
608 indio_dev->modes = INDIO_DIRECT_MODE;
609 indio_dev->info = &mlx90614_info;
611 ret = mlx90614_probe_num_ir_sensors(client);
614 dev_dbg(&client->dev, "Found single sensor");
615 indio_dev->channels = mlx90614_channels;
616 indio_dev->num_channels = 2;
619 dev_dbg(&client->dev, "Found dual sensor");
620 indio_dev->channels = mlx90614_channels;
621 indio_dev->num_channels = 3;
627 if (data->wakeup_gpio) {
628 pm_runtime_set_autosuspend_delay(&client->dev,
629 MLX90614_AUTOSLEEP_DELAY);
630 pm_runtime_use_autosuspend(&client->dev);
631 pm_runtime_set_active(&client->dev);
632 pm_runtime_enable(&client->dev);
635 return iio_device_register(indio_dev);
638 static void mlx90614_remove(struct i2c_client *client)
640 struct iio_dev *indio_dev = i2c_get_clientdata(client);
641 struct mlx90614_data *data = iio_priv(indio_dev);
643 iio_device_unregister(indio_dev);
645 if (data->wakeup_gpio) {
646 pm_runtime_disable(&client->dev);
647 if (!pm_runtime_status_suspended(&client->dev))
648 mlx90614_sleep(data);
649 pm_runtime_set_suspended(&client->dev);
653 static const struct mlx_chip_info mlx90614_chip_info = {
654 .op_eeprom_emissivity = MLX90614_OP_EEPROM | 0x04,
655 .op_eeprom_config1 = MLX90614_OP_EEPROM | 0x05,
656 .op_ram_ta = MLX90614_OP_RAM | 0x06,
657 .op_ram_tobj1 = MLX90614_OP_RAM | 0x07,
658 .op_ram_tobj2 = MLX90614_OP_RAM | 0x08,
659 .op_sleep = MLX90614_OP_SLEEP,
660 .dual_channel = true,
661 .wakeup_delay_ms = MLX90614_TIMING_WAKEUP,
662 .emissivity_max = 65535,
663 .fir_config_mask = MLX90614_CONFIG_FIR_MASK,
664 .iir_config_mask = MLX90614_CONFIG_IIR_MASK,
665 .iir_valid_offset = 0,
666 .iir_values = { 77, 31, 20, 15, 723, 153, 110, 86 },
668 { 0, 150000 }, /* 13% ~= 0.15 Hz */
669 { 0, 200000 }, /* 17% ~= 0.20 Hz */
670 { 0, 310000 }, /* 25% ~= 0.31 Hz */
671 { 0, 770000 }, /* 50% ~= 0.77 Hz */
672 { 0, 860000 }, /* 57% ~= 0.86 Hz */
673 { 1, 100000 }, /* 67% ~= 1.10 Hz */
674 { 1, 530000 }, /* 80% ~= 1.53 Hz */
675 { 7, 230000 } /* 100% ~= 7.23 Hz */
679 static const struct mlx_chip_info mlx90615_chip_info = {
680 .op_eeprom_emissivity = MLX90615_OP_EEPROM | 0x03,
681 .op_eeprom_config1 = MLX90615_OP_EEPROM | 0x02,
682 .op_ram_ta = MLX90615_OP_RAM | 0x06,
683 .op_ram_tobj1 = MLX90615_OP_RAM | 0x07,
684 .op_ram_tobj2 = MLX90615_OP_RAM | 0x08,
685 .op_sleep = MLX90615_OP_SLEEP,
686 .dual_channel = false,
687 .wakeup_delay_ms = MLX90615_TIMING_WAKEUP,
688 .emissivity_max = 16383,
689 .fir_config_mask = 0, /* MLX90615 FIR is fixed */
690 .iir_config_mask = MLX90615_CONFIG_IIR_MASK,
691 /* IIR value 0 is FORBIDDEN COMBINATION on MLX90615 */
692 .iir_valid_offset = 1,
693 .iir_values = { 500, 50, 30, 20, 15, 13, 10 },
695 { 0, 100000 }, /* 14% ~= 0.10 Hz */
696 { 0, 130000 }, /* 17% ~= 0.13 Hz */
697 { 0, 150000 }, /* 20% ~= 0.15 Hz */
698 { 0, 200000 }, /* 25% ~= 0.20 Hz */
699 { 0, 300000 }, /* 33% ~= 0.30 Hz */
700 { 0, 500000 }, /* 50% ~= 0.50 Hz */
701 { 5, 000000 }, /* 100% ~= 5.00 Hz */
705 static const struct i2c_device_id mlx90614_id[] = {
706 { "mlx90614", .driver_data = (kernel_ulong_t)&mlx90614_chip_info },
707 { "mlx90615", .driver_data = (kernel_ulong_t)&mlx90615_chip_info },
710 MODULE_DEVICE_TABLE(i2c, mlx90614_id);
712 static const struct of_device_id mlx90614_of_match[] = {
713 { .compatible = "melexis,mlx90614", .data = &mlx90614_chip_info },
714 { .compatible = "melexis,mlx90615", .data = &mlx90615_chip_info },
717 MODULE_DEVICE_TABLE(of, mlx90614_of_match);
719 static int mlx90614_pm_suspend(struct device *dev)
721 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
722 struct mlx90614_data *data = iio_priv(indio_dev);
724 if (data->wakeup_gpio && pm_runtime_active(dev))
725 return mlx90614_sleep(data);
730 static int mlx90614_pm_resume(struct device *dev)
732 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
733 struct mlx90614_data *data = iio_priv(indio_dev);
736 if (data->wakeup_gpio) {
737 err = mlx90614_wakeup(data);
741 pm_runtime_disable(dev);
742 pm_runtime_set_active(dev);
743 pm_runtime_enable(dev);
749 static int mlx90614_pm_runtime_suspend(struct device *dev)
751 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
752 struct mlx90614_data *data = iio_priv(indio_dev);
754 return mlx90614_sleep(data);
757 static int mlx90614_pm_runtime_resume(struct device *dev)
759 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
760 struct mlx90614_data *data = iio_priv(indio_dev);
762 return mlx90614_wakeup(data);
765 static const struct dev_pm_ops mlx90614_pm_ops = {
766 SYSTEM_SLEEP_PM_OPS(mlx90614_pm_suspend, mlx90614_pm_resume)
767 RUNTIME_PM_OPS(mlx90614_pm_runtime_suspend,
768 mlx90614_pm_runtime_resume, NULL)
771 static struct i2c_driver mlx90614_driver = {
774 .of_match_table = mlx90614_of_match,
775 .pm = pm_ptr(&mlx90614_pm_ops),
777 .probe = mlx90614_probe,
778 .remove = mlx90614_remove,
779 .id_table = mlx90614_id,
781 module_i2c_driver(mlx90614_driver);
783 MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
784 MODULE_AUTHOR("Vianney le Clément de Saint-Marcq <vianney.leclement@essensium.com>");
785 MODULE_AUTHOR("Crt Mori <cmo@melexis.com>");
786 MODULE_DESCRIPTION("Melexis MLX90614 contactless IR temperature sensor driver");
787 MODULE_LICENSE("GPL");