1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * atlas-sensor.c - Support for Atlas Scientific OEM SM sensors
4  *
5  * Copyright (C) 2015-2019 Konsulko Group
6  * Author: Matt Ranostay <matt.ranostay@konsulko.com>
7  */
8 
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/interrupt.h>
12 #include <linux/delay.h>
13 #include <linux/mutex.h>
14 #include <linux/err.h>
15 #include <linux/irq.h>
16 #include <linux/irq_work.h>
17 #include <linux/i2c.h>
18 #include <linux/of_device.h>
19 #include <linux/regmap.h>
20 #include <linux/iio/iio.h>
21 #include <linux/iio/buffer.h>
22 #include <linux/iio/trigger.h>
23 #include <linux/iio/trigger_consumer.h>
24 #include <linux/iio/triggered_buffer.h>
25 #include <linux/pm_runtime.h>
26 
27 #define ATLAS_REGMAP_NAME	"atlas_regmap"
28 #define ATLAS_DRV_NAME		"atlas"
29 
30 #define ATLAS_REG_DEV_TYPE		0x00
31 #define ATLAS_REG_DEV_VERSION		0x01
32 
33 #define ATLAS_REG_INT_CONTROL		0x04
34 #define ATLAS_REG_INT_CONTROL_EN	BIT(3)
35 
36 #define ATLAS_REG_PWR_CONTROL		0x06
37 
38 #define ATLAS_REG_PH_CALIB_STATUS	0x0d
39 #define ATLAS_REG_PH_CALIB_STATUS_MASK	0x07
40 #define ATLAS_REG_PH_CALIB_STATUS_LOW	BIT(0)
41 #define ATLAS_REG_PH_CALIB_STATUS_MID	BIT(1)
42 #define ATLAS_REG_PH_CALIB_STATUS_HIGH	BIT(2)
43 
44 #define ATLAS_REG_EC_CALIB_STATUS		0x0f
45 #define ATLAS_REG_EC_CALIB_STATUS_MASK		0x0f
46 #define ATLAS_REG_EC_CALIB_STATUS_DRY		BIT(0)
47 #define ATLAS_REG_EC_CALIB_STATUS_SINGLE	BIT(1)
48 #define ATLAS_REG_EC_CALIB_STATUS_LOW		BIT(2)
49 #define ATLAS_REG_EC_CALIB_STATUS_HIGH		BIT(3)
50 
51 #define ATLAS_REG_PH_TEMP_DATA		0x0e
52 #define ATLAS_REG_PH_DATA		0x16
53 
54 #define ATLAS_REG_EC_PROBE		0x08
55 #define ATLAS_REG_EC_TEMP_DATA		0x10
56 #define ATLAS_REG_EC_DATA		0x18
57 #define ATLAS_REG_TDS_DATA		0x1c
58 #define ATLAS_REG_PSS_DATA		0x20
59 
60 #define ATLAS_REG_ORP_CALIB_STATUS	0x0d
61 #define ATLAS_REG_ORP_DATA		0x0e
62 
63 #define ATLAS_PH_INT_TIME_IN_MS		450
64 #define ATLAS_EC_INT_TIME_IN_MS		650
65 #define ATLAS_ORP_INT_TIME_IN_MS	450
66 
67 enum {
68 	ATLAS_PH_SM,
69 	ATLAS_EC_SM,
70 	ATLAS_ORP_SM,
71 };
72 
73 struct atlas_data {
74 	struct i2c_client *client;
75 	struct iio_trigger *trig;
76 	struct atlas_device *chip;
77 	struct regmap *regmap;
78 	struct irq_work work;
79 
80 	__be32 buffer[6]; /* 96-bit data + 32-bit pad + 64-bit timestamp */
81 };
82 
83 static const struct regmap_config atlas_regmap_config = {
84 	.name = ATLAS_REGMAP_NAME,
85 	.reg_bits = 8,
86 	.val_bits = 8,
87 };
88 
89 static int atlas_buffer_num_channels(const struct iio_chan_spec *spec)
90 {
91 	int idx = 0;
92 
93 	for (; spec->type != IIO_TIMESTAMP; spec++)
94 		idx++;
95 
96 	return idx;
97 };
98 
99 static const struct iio_chan_spec atlas_ph_channels[] = {
100 	{
101 		.type = IIO_PH,
102 		.address = ATLAS_REG_PH_DATA,
103 		.info_mask_separate =
104 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
105 		.scan_index = 0,
106 		.scan_type = {
107 			.sign = 'u',
108 			.realbits = 32,
109 			.storagebits = 32,
110 			.endianness = IIO_BE,
111 		},
112 	},
113 	IIO_CHAN_SOFT_TIMESTAMP(1),
114 	{
115 		.type = IIO_TEMP,
116 		.address = ATLAS_REG_PH_TEMP_DATA,
117 		.info_mask_separate =
118 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
119 		.output = 1,
120 		.scan_index = -1
121 	},
122 };
123 
124 #define ATLAS_EC_CHANNEL(_idx, _addr) \
125 	{\
126 		.type = IIO_CONCENTRATION, \
127 		.indexed = 1, \
128 		.channel = _idx, \
129 		.address = _addr, \
130 		.info_mask_separate = \
131 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \
132 		.scan_index = _idx + 1, \
133 		.scan_type = { \
134 			.sign = 'u', \
135 			.realbits = 32, \
136 			.storagebits = 32, \
137 			.endianness = IIO_BE, \
138 		}, \
139 	}
140 
141 static const struct iio_chan_spec atlas_ec_channels[] = {
142 	{
143 		.type = IIO_ELECTRICALCONDUCTIVITY,
144 		.address = ATLAS_REG_EC_DATA,
145 		.info_mask_separate =
146 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
147 		.scan_index = 0,
148 		.scan_type = {
149 			.sign = 'u',
150 			.realbits = 32,
151 			.storagebits = 32,
152 			.endianness = IIO_BE,
153 		},
154 	},
155 	ATLAS_EC_CHANNEL(0, ATLAS_REG_TDS_DATA),
156 	ATLAS_EC_CHANNEL(1, ATLAS_REG_PSS_DATA),
157 	IIO_CHAN_SOFT_TIMESTAMP(3),
158 	{
159 		.type = IIO_TEMP,
160 		.address = ATLAS_REG_EC_TEMP_DATA,
161 		.info_mask_separate =
162 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
163 		.output = 1,
164 		.scan_index = -1
165 	},
166 };
167 
168 static const struct iio_chan_spec atlas_orp_channels[] = {
169 	{
170 		.type = IIO_VOLTAGE,
171 		.address = ATLAS_REG_ORP_DATA,
172 		.info_mask_separate =
173 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
174 		.scan_index = 0,
175 		.scan_type = {
176 			.sign = 's',
177 			.realbits = 32,
178 			.storagebits = 32,
179 			.endianness = IIO_BE,
180 		},
181 	},
182 	IIO_CHAN_SOFT_TIMESTAMP(1),
183 };
184 
185 static int atlas_check_ph_calibration(struct atlas_data *data)
186 {
187 	struct device *dev = &data->client->dev;
188 	int ret;
189 	unsigned int val;
190 
191 	ret = regmap_read(data->regmap, ATLAS_REG_PH_CALIB_STATUS, &val);
192 	if (ret)
193 		return ret;
194 
195 	if (!(val & ATLAS_REG_PH_CALIB_STATUS_MASK)) {
196 		dev_warn(dev, "device has not been calibrated\n");
197 		return 0;
198 	}
199 
200 	if (!(val & ATLAS_REG_PH_CALIB_STATUS_LOW))
201 		dev_warn(dev, "device missing low point calibration\n");
202 
203 	if (!(val & ATLAS_REG_PH_CALIB_STATUS_MID))
204 		dev_warn(dev, "device missing mid point calibration\n");
205 
206 	if (!(val & ATLAS_REG_PH_CALIB_STATUS_HIGH))
207 		dev_warn(dev, "device missing high point calibration\n");
208 
209 	return 0;
210 }
211 
212 static int atlas_check_ec_calibration(struct atlas_data *data)
213 {
214 	struct device *dev = &data->client->dev;
215 	int ret;
216 	unsigned int val;
217 	__be16	rval;
218 
219 	ret = regmap_bulk_read(data->regmap, ATLAS_REG_EC_PROBE, &rval, 2);
220 	if (ret)
221 		return ret;
222 
223 	val = be16_to_cpu(rval);
224 	dev_info(dev, "probe set to K = %d.%.2d", val / 100, val % 100);
225 
226 	ret = regmap_read(data->regmap, ATLAS_REG_EC_CALIB_STATUS, &val);
227 	if (ret)
228 		return ret;
229 
230 	if (!(val & ATLAS_REG_EC_CALIB_STATUS_MASK)) {
231 		dev_warn(dev, "device has not been calibrated\n");
232 		return 0;
233 	}
234 
235 	if (!(val & ATLAS_REG_EC_CALIB_STATUS_DRY))
236 		dev_warn(dev, "device missing dry point calibration\n");
237 
238 	if (val & ATLAS_REG_EC_CALIB_STATUS_SINGLE) {
239 		dev_warn(dev, "device using single point calibration\n");
240 	} else {
241 		if (!(val & ATLAS_REG_EC_CALIB_STATUS_LOW))
242 			dev_warn(dev, "device missing low point calibration\n");
243 
244 		if (!(val & ATLAS_REG_EC_CALIB_STATUS_HIGH))
245 			dev_warn(dev, "device missing high point calibration\n");
246 	}
247 
248 	return 0;
249 }
250 
251 static int atlas_check_orp_calibration(struct atlas_data *data)
252 {
253 	struct device *dev = &data->client->dev;
254 	int ret;
255 	unsigned int val;
256 
257 	ret = regmap_read(data->regmap, ATLAS_REG_ORP_CALIB_STATUS, &val);
258 	if (ret)
259 		return ret;
260 
261 	if (!val)
262 		dev_warn(dev, "device has not been calibrated\n");
263 
264 	return 0;
265 };
266 
267 struct atlas_device {
268 	const struct iio_chan_spec *channels;
269 	int num_channels;
270 	int data_reg;
271 
272 	int (*calibration)(struct atlas_data *data);
273 	int delay;
274 };
275 
276 static struct atlas_device atlas_devices[] = {
277 	[ATLAS_PH_SM] = {
278 				.channels = atlas_ph_channels,
279 				.num_channels = 3,
280 				.data_reg = ATLAS_REG_PH_DATA,
281 				.calibration = &atlas_check_ph_calibration,
282 				.delay = ATLAS_PH_INT_TIME_IN_MS,
283 	},
284 	[ATLAS_EC_SM] = {
285 				.channels = atlas_ec_channels,
286 				.num_channels = 5,
287 				.data_reg = ATLAS_REG_EC_DATA,
288 				.calibration = &atlas_check_ec_calibration,
289 				.delay = ATLAS_EC_INT_TIME_IN_MS,
290 	},
291 	[ATLAS_ORP_SM] = {
292 				.channels = atlas_orp_channels,
293 				.num_channels = 2,
294 				.data_reg = ATLAS_REG_ORP_DATA,
295 				.calibration = &atlas_check_orp_calibration,
296 				.delay = ATLAS_ORP_INT_TIME_IN_MS,
297 	},
298 };
299 
300 static int atlas_set_powermode(struct atlas_data *data, int on)
301 {
302 	return regmap_write(data->regmap, ATLAS_REG_PWR_CONTROL, on);
303 }
304 
305 static int atlas_set_interrupt(struct atlas_data *data, bool state)
306 {
307 	return regmap_update_bits(data->regmap, ATLAS_REG_INT_CONTROL,
308 				  ATLAS_REG_INT_CONTROL_EN,
309 				  state ? ATLAS_REG_INT_CONTROL_EN : 0);
310 }
311 
312 static int atlas_buffer_postenable(struct iio_dev *indio_dev)
313 {
314 	struct atlas_data *data = iio_priv(indio_dev);
315 	int ret;
316 
317 	ret = iio_triggered_buffer_postenable(indio_dev);
318 	if (ret)
319 		return ret;
320 
321 	ret = pm_runtime_get_sync(&data->client->dev);
322 	if (ret < 0) {
323 		pm_runtime_put_noidle(&data->client->dev);
324 		return ret;
325 	}
326 
327 	return atlas_set_interrupt(data, true);
328 }
329 
330 static int atlas_buffer_predisable(struct iio_dev *indio_dev)
331 {
332 	struct atlas_data *data = iio_priv(indio_dev);
333 	int ret;
334 
335 	ret = atlas_set_interrupt(data, false);
336 	if (ret)
337 		return ret;
338 
339 	pm_runtime_mark_last_busy(&data->client->dev);
340 	ret = pm_runtime_put_autosuspend(&data->client->dev);
341 	if (ret)
342 		return ret;
343 
344 	return iio_triggered_buffer_predisable(indio_dev);
345 }
346 
347 static const struct iio_trigger_ops atlas_interrupt_trigger_ops = {
348 };
349 
350 static const struct iio_buffer_setup_ops atlas_buffer_setup_ops = {
351 	.postenable = atlas_buffer_postenable,
352 	.predisable = atlas_buffer_predisable,
353 };
354 
355 static void atlas_work_handler(struct irq_work *work)
356 {
357 	struct atlas_data *data = container_of(work, struct atlas_data, work);
358 
359 	iio_trigger_poll(data->trig);
360 }
361 
362 static irqreturn_t atlas_trigger_handler(int irq, void *private)
363 {
364 	struct iio_poll_func *pf = private;
365 	struct iio_dev *indio_dev = pf->indio_dev;
366 	struct atlas_data *data = iio_priv(indio_dev);
367 	int channels = atlas_buffer_num_channels(data->chip->channels);
368 	int ret;
369 
370 	ret = regmap_bulk_read(data->regmap, data->chip->data_reg,
371 			      (u8 *) &data->buffer,
372 			      sizeof(__be32) * channels);
373 
374 	if (!ret)
375 		iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
376 				iio_get_time_ns(indio_dev));
377 
378 	iio_trigger_notify_done(indio_dev->trig);
379 
380 	return IRQ_HANDLED;
381 }
382 
383 static irqreturn_t atlas_interrupt_handler(int irq, void *private)
384 {
385 	struct iio_dev *indio_dev = private;
386 	struct atlas_data *data = iio_priv(indio_dev);
387 
388 	irq_work_queue(&data->work);
389 
390 	return IRQ_HANDLED;
391 }
392 
393 static int atlas_read_measurement(struct atlas_data *data, int reg, __be32 *val)
394 {
395 	struct device *dev = &data->client->dev;
396 	int suspended = pm_runtime_suspended(dev);
397 	int ret;
398 
399 	ret = pm_runtime_get_sync(dev);
400 	if (ret < 0) {
401 		pm_runtime_put_noidle(dev);
402 		return ret;
403 	}
404 
405 	if (suspended)
406 		msleep(data->chip->delay);
407 
408 	ret = regmap_bulk_read(data->regmap, reg, (u8 *) val, sizeof(*val));
409 
410 	pm_runtime_mark_last_busy(dev);
411 	pm_runtime_put_autosuspend(dev);
412 
413 	return ret;
414 }
415 
416 static int atlas_read_raw(struct iio_dev *indio_dev,
417 			  struct iio_chan_spec const *chan,
418 			  int *val, int *val2, long mask)
419 {
420 	struct atlas_data *data = iio_priv(indio_dev);
421 
422 	switch (mask) {
423 	case IIO_CHAN_INFO_RAW: {
424 		int ret;
425 		__be32 reg;
426 
427 		switch (chan->type) {
428 		case IIO_TEMP:
429 			ret = regmap_bulk_read(data->regmap, chan->address,
430 					      (u8 *) &reg, sizeof(reg));
431 			break;
432 		case IIO_PH:
433 		case IIO_CONCENTRATION:
434 		case IIO_ELECTRICALCONDUCTIVITY:
435 		case IIO_VOLTAGE:
436 			ret = iio_device_claim_direct_mode(indio_dev);
437 			if (ret)
438 				return ret;
439 
440 			ret = atlas_read_measurement(data, chan->address, &reg);
441 
442 			iio_device_release_direct_mode(indio_dev);
443 			break;
444 		default:
445 			ret = -EINVAL;
446 		}
447 
448 		if (!ret) {
449 			*val = be32_to_cpu(reg);
450 			ret = IIO_VAL_INT;
451 		}
452 		return ret;
453 	}
454 	case IIO_CHAN_INFO_SCALE:
455 		switch (chan->type) {
456 		case IIO_TEMP:
457 			*val = 10;
458 			return IIO_VAL_INT;
459 		case IIO_PH:
460 			*val = 1; /* 0.001 */
461 			*val2 = 1000;
462 			break;
463 		case IIO_ELECTRICALCONDUCTIVITY:
464 			*val = 1; /* 0.00001 */
465 			*val2 = 100000;
466 			break;
467 		case IIO_CONCENTRATION:
468 			*val = 0; /* 0.000000001 */
469 			*val2 = 1000;
470 			return IIO_VAL_INT_PLUS_NANO;
471 		case IIO_VOLTAGE:
472 			*val = 1; /* 0.1 */
473 			*val2 = 10;
474 			break;
475 		default:
476 			return -EINVAL;
477 		}
478 		return IIO_VAL_FRACTIONAL;
479 	}
480 
481 	return -EINVAL;
482 }
483 
484 static int atlas_write_raw(struct iio_dev *indio_dev,
485 			   struct iio_chan_spec const *chan,
486 			   int val, int val2, long mask)
487 {
488 	struct atlas_data *data = iio_priv(indio_dev);
489 	__be32 reg = cpu_to_be32(val / 10);
490 
491 	if (val2 != 0 || val < 0 || val > 20000)
492 		return -EINVAL;
493 
494 	if (mask != IIO_CHAN_INFO_RAW || chan->type != IIO_TEMP)
495 		return -EINVAL;
496 
497 	return regmap_bulk_write(data->regmap, chan->address,
498 				 &reg, sizeof(reg));
499 }
500 
501 static const struct iio_info atlas_info = {
502 	.read_raw = atlas_read_raw,
503 	.write_raw = atlas_write_raw,
504 };
505 
506 static const struct i2c_device_id atlas_id[] = {
507 	{ "atlas-ph-sm", ATLAS_PH_SM},
508 	{ "atlas-ec-sm", ATLAS_EC_SM},
509 	{ "atlas-orp-sm", ATLAS_ORP_SM},
510 	{}
511 };
512 MODULE_DEVICE_TABLE(i2c, atlas_id);
513 
514 static const struct of_device_id atlas_dt_ids[] = {
515 	{ .compatible = "atlas,ph-sm", .data = (void *)ATLAS_PH_SM, },
516 	{ .compatible = "atlas,ec-sm", .data = (void *)ATLAS_EC_SM, },
517 	{ .compatible = "atlas,orp-sm", .data = (void *)ATLAS_ORP_SM, },
518 	{ }
519 };
520 MODULE_DEVICE_TABLE(of, atlas_dt_ids);
521 
522 static int atlas_probe(struct i2c_client *client,
523 		       const struct i2c_device_id *id)
524 {
525 	struct atlas_data *data;
526 	struct atlas_device *chip;
527 	const struct of_device_id *of_id;
528 	struct iio_trigger *trig;
529 	struct iio_dev *indio_dev;
530 	int ret;
531 
532 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
533 	if (!indio_dev)
534 		return -ENOMEM;
535 
536 	of_id = of_match_device(atlas_dt_ids, &client->dev);
537 	if (!of_id)
538 		chip = &atlas_devices[id->driver_data];
539 	else
540 		chip = &atlas_devices[(unsigned long)of_id->data];
541 
542 	indio_dev->info = &atlas_info;
543 	indio_dev->name = ATLAS_DRV_NAME;
544 	indio_dev->channels = chip->channels;
545 	indio_dev->num_channels = chip->num_channels;
546 	indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE;
547 	indio_dev->dev.parent = &client->dev;
548 
549 	trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
550 				      indio_dev->name, indio_dev->id);
551 
552 	if (!trig)
553 		return -ENOMEM;
554 
555 	data = iio_priv(indio_dev);
556 	data->client = client;
557 	data->trig = trig;
558 	data->chip = chip;
559 	trig->dev.parent = indio_dev->dev.parent;
560 	trig->ops = &atlas_interrupt_trigger_ops;
561 	iio_trigger_set_drvdata(trig, indio_dev);
562 
563 	i2c_set_clientdata(client, indio_dev);
564 
565 	data->regmap = devm_regmap_init_i2c(client, &atlas_regmap_config);
566 	if (IS_ERR(data->regmap)) {
567 		dev_err(&client->dev, "regmap initialization failed\n");
568 		return PTR_ERR(data->regmap);
569 	}
570 
571 	ret = pm_runtime_set_active(&client->dev);
572 	if (ret)
573 		return ret;
574 
575 	if (client->irq <= 0) {
576 		dev_err(&client->dev, "no valid irq defined\n");
577 		return -EINVAL;
578 	}
579 
580 	ret = chip->calibration(data);
581 	if (ret)
582 		return ret;
583 
584 	ret = iio_trigger_register(trig);
585 	if (ret) {
586 		dev_err(&client->dev, "failed to register trigger\n");
587 		return ret;
588 	}
589 
590 	ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
591 		&atlas_trigger_handler, &atlas_buffer_setup_ops);
592 	if (ret) {
593 		dev_err(&client->dev, "cannot setup iio trigger\n");
594 		goto unregister_trigger;
595 	}
596 
597 	init_irq_work(&data->work, atlas_work_handler);
598 
599 	/* interrupt pin toggles on new conversion */
600 	ret = devm_request_threaded_irq(&client->dev, client->irq,
601 					NULL, atlas_interrupt_handler,
602 					IRQF_TRIGGER_RISING |
603 					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
604 					"atlas_irq",
605 					indio_dev);
606 	if (ret) {
607 		dev_err(&client->dev, "request irq (%d) failed\n", client->irq);
608 		goto unregister_buffer;
609 	}
610 
611 	ret = atlas_set_powermode(data, 1);
612 	if (ret) {
613 		dev_err(&client->dev, "cannot power device on");
614 		goto unregister_buffer;
615 	}
616 
617 	pm_runtime_enable(&client->dev);
618 	pm_runtime_set_autosuspend_delay(&client->dev, 2500);
619 	pm_runtime_use_autosuspend(&client->dev);
620 
621 	ret = iio_device_register(indio_dev);
622 	if (ret) {
623 		dev_err(&client->dev, "unable to register device\n");
624 		goto unregister_pm;
625 	}
626 
627 	return 0;
628 
629 unregister_pm:
630 	pm_runtime_disable(&client->dev);
631 	atlas_set_powermode(data, 0);
632 
633 unregister_buffer:
634 	iio_triggered_buffer_cleanup(indio_dev);
635 
636 unregister_trigger:
637 	iio_trigger_unregister(data->trig);
638 
639 	return ret;
640 }
641 
642 static int atlas_remove(struct i2c_client *client)
643 {
644 	struct iio_dev *indio_dev = i2c_get_clientdata(client);
645 	struct atlas_data *data = iio_priv(indio_dev);
646 
647 	iio_device_unregister(indio_dev);
648 	iio_triggered_buffer_cleanup(indio_dev);
649 	iio_trigger_unregister(data->trig);
650 
651 	pm_runtime_disable(&client->dev);
652 	pm_runtime_set_suspended(&client->dev);
653 	pm_runtime_put_noidle(&client->dev);
654 
655 	return atlas_set_powermode(data, 0);
656 }
657 
658 #ifdef CONFIG_PM
659 static int atlas_runtime_suspend(struct device *dev)
660 {
661 	struct atlas_data *data =
662 		     iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
663 
664 	return atlas_set_powermode(data, 0);
665 }
666 
667 static int atlas_runtime_resume(struct device *dev)
668 {
669 	struct atlas_data *data =
670 		     iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
671 
672 	return atlas_set_powermode(data, 1);
673 }
674 #endif
675 
676 static const struct dev_pm_ops atlas_pm_ops = {
677 	SET_RUNTIME_PM_OPS(atlas_runtime_suspend,
678 			   atlas_runtime_resume, NULL)
679 };
680 
681 static struct i2c_driver atlas_driver = {
682 	.driver = {
683 		.name	= ATLAS_DRV_NAME,
684 		.of_match_table	= of_match_ptr(atlas_dt_ids),
685 		.pm	= &atlas_pm_ops,
686 	},
687 	.probe		= atlas_probe,
688 	.remove		= atlas_remove,
689 	.id_table	= atlas_id,
690 };
691 module_i2c_driver(atlas_driver);
692 
693 MODULE_AUTHOR("Matt Ranostay <matt.ranostay@konsulko.com>");
694 MODULE_DESCRIPTION("Atlas Scientific SM sensors");
695 MODULE_LICENSE("GPL");
696