1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2023 Carl Zeiss Meditec AG
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #define DT_DRV_COMPAT adi_adltc2990
7 
8 #include <zephyr/sys/util.h>
9 #include <zephyr/drivers/i2c.h>
10 
11 #include "adltc2990_reg.h"
12 #include "adltc2990.h"
13 
14 #include <zephyr/logging/log.h>
15 LOG_MODULE_REGISTER(adltc2990, CONFIG_SENSOR_LOG_LEVEL);
16 
adltc2990_get_v1_v2_measurement_modes(uint8_t mode_4_3,uint8_t mode_2_0)17 static enum adltc2990_monitoring_type adltc2990_get_v1_v2_measurement_modes(uint8_t mode_4_3,
18 									    uint8_t mode_2_0)
19 {
20 	if (mode_2_0 > ADLTC2990_MODE_2_0_MAX_VALUE || mode_4_3 > ADLTC2990_MODE_4_3_MAX_VALUE) {
21 		LOG_ERR("Invalid Measurement Mode");
22 		return -EINVAL;
23 	}
24 	if (mode_4_3 == ADLTC2990_MEASURE_INTERNAL_TEMPERATURE_ONLY ||
25 	    mode_4_3 == ADLTC2990_MEASURE_PINS_V3_V4_ONLY) {
26 		return NOTHING;
27 	}
28 
29 	enum adltc2990_monitoring_type type = NOTHING;
30 
31 	switch (mode_2_0) {
32 	case ADLTC2990_MODE_V1_V2_TR2:
33 	case ADLTC2990_MODE_V1_V2_V3_V4: {
34 		type = VOLTAGE_SINGLEENDED;
35 		break;
36 	}
37 	case ADLTC2990_MODE_V1_MINUS_V2_TR2:
38 	case ADLTC2990_MODE_V1_MINUS_V2_V3_V4:
39 	case ADLTC2990_MODE_V1_MINUS_V2_V3_MINUS_V4: {
40 		type = VOLTAGE_DIFFERENTIAL;
41 		break;
42 	}
43 	case ADLTC2990_MODE_TR1_V3_V4:
44 	case ADLTC2990_MODE_TR1_V3_MINUS_V4: {
45 	case ADLTC2990_MODE_TR1_TR2:
46 		type = TEMPERATURE;
47 		break;
48 	}
49 	default: {
50 		break;
51 	}
52 	}
53 	return type;
54 }
55 
adltc2990_get_v3_v4_measurement_modes(uint8_t mode_4_3,uint8_t mode_2_0)56 static enum adltc2990_monitoring_type adltc2990_get_v3_v4_measurement_modes(uint8_t mode_4_3,
57 									    uint8_t mode_2_0)
58 {
59 	if (mode_2_0 > ADLTC2990_MODE_2_0_MAX_VALUE || mode_4_3 > ADLTC2990_MODE_4_3_MAX_VALUE) {
60 		LOG_ERR("Invalid Measurement Mode");
61 		return -EINVAL;
62 	}
63 	if (mode_4_3 == ADLTC2990_MEASURE_INTERNAL_TEMPERATURE_ONLY ||
64 	    mode_4_3 == ADLTC2990_MEASURE_PINS_V1_V2_ONLY) {
65 		return NOTHING;
66 	}
67 
68 	enum adltc2990_monitoring_type type = NOTHING;
69 
70 	switch (mode_2_0) {
71 	case ADLTC2990_MODE_V1_V2_TR2:
72 	case ADLTC2990_MODE_V1_MINUS_V2_TR2:
73 	case ADLTC2990_MODE_TR1_TR2: {
74 		type = TEMPERATURE;
75 		break;
76 	}
77 
78 	case ADLTC2990_MODE_V1_MINUS_V2_V3_V4:
79 	case ADLTC2990_MODE_TR1_V3_V4:
80 	case ADLTC2990_MODE_V1_V2_V3_V4: {
81 		type = VOLTAGE_SINGLEENDED;
82 		break;
83 	}
84 	case ADLTC2990_MODE_TR1_V3_MINUS_V4:
85 	case ADLTC2990_MODE_V1_MINUS_V2_V3_MINUS_V4: {
86 		type = VOLTAGE_DIFFERENTIAL;
87 		break;
88 	}
89 	default: {
90 		break;
91 	}
92 	}
93 	return type;
94 }
95 
adltc2990_is_busy(const struct device * dev,bool * is_busy)96 static int adltc2990_is_busy(const struct device *dev, bool *is_busy)
97 {
98 	const struct adltc2990_config *cfg = dev->config;
99 	uint8_t status_reg = 0;
100 	int ret;
101 
102 	ret = i2c_reg_read_byte_dt(&cfg->bus, ADLTC2990_REG_STATUS, &status_reg);
103 	if (ret) {
104 		return ret;
105 	}
106 
107 	*is_busy = status_reg & BIT(0);
108 
109 	return 0;
110 }
111 
adltc2990_get_v1_v2_val(const struct device * dev,struct sensor_value * val,uint8_t num_values,uint8_t * const offset_index)112 static void adltc2990_get_v1_v2_val(const struct device *dev, struct sensor_value *val,
113 				    uint8_t num_values, uint8_t *const offset_index)
114 {
115 	struct adltc2990_data *data = dev->data;
116 
117 	for (uint8_t index = 0; index < num_values; index++) {
118 		val[index].val1 = data->pins_v1_v2_values[index] / 1000000;
119 		val[index].val2 = data->pins_v1_v2_values[index] % 1000000;
120 		*offset_index = index + 1;
121 	}
122 }
123 
adltc2990_get_v3_v4_val(const struct device * dev,struct sensor_value * val,uint8_t num_values,uint8_t const * const offset)124 static void adltc2990_get_v3_v4_val(const struct device *dev, struct sensor_value *val,
125 				    uint8_t num_values, uint8_t const *const offset)
126 {
127 	struct adltc2990_data *data = dev->data;
128 
129 	uint8_t offset_index = *offset;
130 
131 	for (uint8_t index = 0; index < num_values; index++) {
132 		val[index + offset_index].val1 = data->pins_v3_v4_values[index] / 1000000;
133 		val[index + offset_index].val2 = data->pins_v3_v4_values[index] % 1000000;
134 	}
135 }
136 
adltc2990_trigger_measurement(const struct device * dev)137 static int adltc2990_trigger_measurement(const struct device *dev)
138 {
139 	const struct adltc2990_config *cfg = dev->config;
140 
141 	return i2c_reg_write_byte_dt(&cfg->bus, ADLTC2990_REG_TRIGGER, 0x1);
142 }
143 
adltc2990_fetch_property_value(const struct device * dev,enum adltc2990_monitoring_type type,enum adltc2990_monitor_pins pin,int32_t * output)144 static int adltc2990_fetch_property_value(const struct device *dev,
145 					  enum adltc2990_monitoring_type type,
146 					  enum adltc2990_monitor_pins pin,
147 					  int32_t *output)
148 {
149 	const struct adltc2990_config *cfg = dev->config;
150 
151 	uint8_t msb_value = 0, lsb_value = 0;
152 	uint8_t msb_address, lsb_address;
153 
154 	switch (pin) {
155 	case V1: {
156 		msb_address = ADLTC2990_REG_V1_MSB;
157 		lsb_address = ADLTC2990_REG_V1_LSB;
158 		break;
159 	}
160 	case V2: {
161 		msb_address = ADLTC2990_REG_V2_MSB;
162 		lsb_address = ADLTC2990_REG_V2_LSB;
163 		break;
164 	}
165 	case V3: {
166 		msb_address = ADLTC2990_REG_V3_MSB;
167 		lsb_address = ADLTC2990_REG_V3_LSB;
168 		break;
169 	}
170 	case V4: {
171 		msb_address = ADLTC2990_REG_V4_MSB;
172 		lsb_address = ADLTC2990_REG_V4_LSB;
173 		break;
174 	}
175 	case INTERNAL_TEMPERATURE: {
176 		msb_address = ADLTC2990_REG_INTERNAL_TEMP_MSB;
177 		lsb_address = ADLTC2990_REG_INTERNAL_TEMP_LSB;
178 		break;
179 	}
180 	case SUPPLY_VOLTAGE: {
181 		msb_address = ADLTC2990_REG_VCC_MSB;
182 		lsb_address = ADLTC2990_REG_VCC_LSB;
183 		break;
184 	}
185 	default: {
186 		LOG_ERR("Trying to access illegal register");
187 		return -EINVAL;
188 	}
189 	}
190 	int ret;
191 
192 	ret = i2c_reg_read_byte_dt(&cfg->bus, msb_address, &msb_value);
193 	if (ret) {
194 		return ret;
195 	}
196 
197 	ret = i2c_reg_read_byte_dt(&cfg->bus, lsb_address, &lsb_value);
198 	if (ret) {
199 		return ret;
200 	}
201 	uint16_t conversion_factor;
202 	uint8_t negative_bit_index = 14U, sensor_val_divisor = 100U;
203 
204 	if (type == VOLTAGE_SINGLEENDED) {
205 		conversion_factor = ADLTC2990_VOLTAGE_SINGLEENDED_CONVERSION_FACTOR;
206 	} else if (type == VOLTAGE_DIFFERENTIAL) {
207 		conversion_factor = ADLTC2990_VOLTAGE_DIFFERENTIAL_CONVERSION_FACTOR;
208 	} else if (type == TEMPERATURE) {
209 		conversion_factor = ADLTC2990_TEMPERATURE_CONVERSION_FACTOR;
210 		if (cfg->temp_format == ADLTC2990_TEMPERATURE_FORMAT_CELSIUS) {
211 			negative_bit_index = 12U;
212 		}
213 		sensor_val_divisor = 1U;
214 	} else {
215 		LOG_ERR("unknown type");
216 		return -EINVAL;
217 	}
218 
219 	int16_t value = (msb_value << 8) + lsb_value;
220 
221 	int32_t voltage_value = (value << (31 - negative_bit_index)) >> (31 - negative_bit_index);
222 
223 	*output = (voltage_value * conversion_factor) / sensor_val_divisor;
224 
225 	return 0;
226 }
227 
adltc2990_init(const struct device * dev)228 static int adltc2990_init(const struct device *dev)
229 {
230 	const struct adltc2990_config *cfg = dev->config;
231 	int err;
232 
233 	if (!i2c_is_ready_dt(&cfg->bus)) {
234 		LOG_ERR("I2C bus %s not ready", cfg->bus.bus->name);
235 		return -ENODEV;
236 	}
237 
238 	const uint8_t ctrl_reg_setting = cfg->temp_format << 7 | cfg->acq_format << 6 | 0 << 5 |
239 					 cfg->measurement_mode[1] << 3 | cfg->measurement_mode[0];
240 
241 	LOG_DBG("Setting Control Register to: 0x%x", ctrl_reg_setting);
242 	err = i2c_reg_write_byte_dt(&cfg->bus, ADLTC2990_REG_CONTROL, ctrl_reg_setting);
243 	if (err < 0) {
244 		LOG_ERR("configuring for single bus failed: %d", err);
245 		return err;
246 	}
247 
248 	err = adltc2990_trigger_measurement(dev);
249 	if (err < 0) {
250 		LOG_ERR("triggering measurement failed: %d", err);
251 	}
252 
253 	LOG_INF("Initializing ADLTC2990 with name %s", dev->name);
254 	return 0;
255 }
256 
adltc2990_sample_fetch(const struct device * dev,enum sensor_channel chan)257 static int adltc2990_sample_fetch(const struct device *dev, enum sensor_channel chan)
258 {
259 	struct adltc2990_data *data = dev->data;
260 	const struct adltc2990_config *cfg = dev->config;
261 	enum adltc2990_monitoring_type mode_v1_v2 = adltc2990_get_v1_v2_measurement_modes(
262 		cfg->measurement_mode[1], cfg->measurement_mode[0]);
263 	enum adltc2990_monitoring_type mode_v3_v4 = adltc2990_get_v3_v4_measurement_modes(
264 		cfg->measurement_mode[1], cfg->measurement_mode[0]);
265 
266 	float voltage_divider_ratio;
267 	int ret;
268 	int32_t value;
269 
270 	switch (chan) {
271 	case SENSOR_CHAN_DIE_TEMP: {
272 		ret = adltc2990_fetch_property_value(dev, TEMPERATURE, INTERNAL_TEMPERATURE,
273 						     &value);
274 		if (ret) {
275 			return ret;
276 		}
277 		data->internal_temperature = value;
278 		break;
279 	}
280 	case SENSOR_CHAN_CURRENT: {
281 		if (!(mode_v1_v2 == VOLTAGE_DIFFERENTIAL || mode_v3_v4 == VOLTAGE_DIFFERENTIAL)) {
282 			LOG_ERR("Sensor is not configured to measure Current");
283 			return -EINVAL;
284 		}
285 		if (mode_v1_v2 == VOLTAGE_DIFFERENTIAL) {
286 			ret = adltc2990_fetch_property_value(dev, VOLTAGE_DIFFERENTIAL, V1, &value);
287 			if (ret) {
288 				return ret;
289 			}
290 			data->pins_v1_v2_values[0] =
291 				value * (ADLTC2990_MICROOHM_CONVERSION_FACTOR /
292 				 (float)cfg->pins_v1_v2.pins_current_resistor);
293 		}
294 		if (mode_v3_v4 == VOLTAGE_DIFFERENTIAL) {
295 			ret = adltc2990_fetch_property_value(dev, VOLTAGE_DIFFERENTIAL, V3, &value);
296 			if (ret) {
297 				return ret;
298 			}
299 			data->pins_v3_v4_values[0] = value * (ADLTC2990_MICROOHM_CONVERSION_FACTOR /
300 				 (float)cfg->pins_v3_v4.pins_current_resistor);
301 		}
302 		break;
303 	}
304 	case SENSOR_CHAN_VOLTAGE: {
305 		ret = adltc2990_fetch_property_value(dev, VOLTAGE_SINGLEENDED, SUPPLY_VOLTAGE,
306 						     &value);
307 		if (ret) {
308 			return ret;
309 		}
310 		data->supply_voltage = value + 2500000;
311 
312 		if (mode_v1_v2 == VOLTAGE_DIFFERENTIAL) {
313 			ret = adltc2990_fetch_property_value(dev, VOLTAGE_DIFFERENTIAL, V1, &value);
314 			if (ret) {
315 				return ret;
316 			}
317 			data->pins_v1_v2_values[0] = value;
318 		} else if (mode_v1_v2 == VOLTAGE_SINGLEENDED) {
319 			uint32_t v1_r1 = cfg->pins_v1_v2.voltage_divider_resistors.v1_r1_r2[0];
320 
321 			uint32_t v1_r2 = cfg->pins_v1_v2.voltage_divider_resistors.v1_r1_r2[1];
322 
323 			voltage_divider_ratio = (v1_r1 + v1_r2) / (float)v1_r2;
324 			ret = adltc2990_fetch_property_value(dev, VOLTAGE_SINGLEENDED, V1, &value);
325 			if (ret) {
326 				return ret;
327 			}
328 			data->pins_v1_v2_values[0] = value * voltage_divider_ratio;
329 
330 			uint32_t v2_r1 = cfg->pins_v1_v2.voltage_divider_resistors.v2_r1_r2[0];
331 
332 			uint32_t v2_r2 = cfg->pins_v1_v2.voltage_divider_resistors.v2_r1_r2[1];
333 
334 			voltage_divider_ratio = (v2_r1 + v2_r2) / (float)v2_r2;
335 			ret = adltc2990_fetch_property_value(dev, VOLTAGE_SINGLEENDED, V2, &value);
336 			if (ret) {
337 				return ret;
338 			}
339 			data->pins_v1_v2_values[1] = value * voltage_divider_ratio;
340 		}
341 
342 		if (mode_v3_v4 == VOLTAGE_DIFFERENTIAL) {
343 			ret = adltc2990_fetch_property_value(dev, VOLTAGE_DIFFERENTIAL, V3, &value);
344 			if (ret) {
345 				return ret;
346 			}
347 			data->pins_v3_v4_values[0] = value;
348 		} else if (mode_v3_v4 == VOLTAGE_SINGLEENDED) {
349 			uint32_t v3_r1 = cfg->pins_v3_v4.voltage_divider_resistors.v3_r1_r2[0];
350 
351 			uint32_t v3_r2 = cfg->pins_v3_v4.voltage_divider_resistors.v3_r1_r2[1];
352 
353 			voltage_divider_ratio = (v3_r1 + v3_r2) / (float)v3_r2;
354 			ret = adltc2990_fetch_property_value(dev, VOLTAGE_SINGLEENDED, V3, &value);
355 			if (ret) {
356 				return ret;
357 			}
358 			data->pins_v3_v4_values[0] = value * voltage_divider_ratio;
359 
360 			uint32_t v4_r1 = cfg->pins_v3_v4.voltage_divider_resistors.v4_r1_r2[0];
361 
362 			uint32_t v4_r2 = cfg->pins_v3_v4.voltage_divider_resistors.v4_r1_r2[1];
363 
364 			voltage_divider_ratio = (v4_r1 + v4_r2) / (float)v4_r2;
365 
366 			ret = adltc2990_fetch_property_value(dev, VOLTAGE_SINGLEENDED, V4, &value);
367 			if (ret) {
368 				return ret;
369 			}
370 			data->pins_v3_v4_values[1] = value * voltage_divider_ratio;
371 		}
372 		break;
373 	}
374 	case SENSOR_CHAN_AMBIENT_TEMP: {
375 		if (!(mode_v1_v2 == TEMPERATURE || mode_v3_v4 == TEMPERATURE)) {
376 			LOG_ERR("Sensor is not configured to measure Ambient Temperature");
377 			return -EINVAL;
378 		}
379 		if (mode_v1_v2 == TEMPERATURE) {
380 			ret = adltc2990_fetch_property_value(dev, TEMPERATURE, V1, &value);
381 			if (ret) {
382 				return ret;
383 			}
384 			data->pins_v1_v2_values[0] = value;
385 		}
386 		if (mode_v3_v4 == TEMPERATURE) {
387 			ret = adltc2990_fetch_property_value(dev, TEMPERATURE, V3, &value);
388 			if (ret) {
389 				return ret;
390 			}
391 			data->pins_v3_v4_values[0] = value;
392 		}
393 		break;
394 	}
395 	case SENSOR_CHAN_ALL: {
396 		bool is_busy;
397 
398 		ret = adltc2990_is_busy(dev, &is_busy);
399 		if (ret) {
400 			return ret;
401 		}
402 
403 		if (is_busy) {
404 			LOG_INF("ADLTC2990 conversion ongoing");
405 			return -EBUSY;
406 		}
407 		adltc2990_trigger_measurement(dev);
408 		break;
409 	}
410 	default: {
411 		LOG_ERR("does not measure channel: %d", chan);
412 		return -ENOTSUP;
413 	}
414 	}
415 
416 	return 0;
417 }
418 
adltc2990_channel_get(const struct device * dev,enum sensor_channel chan,struct sensor_value * val)419 static int adltc2990_channel_get(const struct device *dev, enum sensor_channel chan,
420 				 struct sensor_value *val)
421 {
422 	if (val == NULL) {
423 		LOG_ERR("Argument of type sensor_value* cannot be null ");
424 		return -EINVAL;
425 	}
426 	struct adltc2990_data *data = dev->data;
427 	const struct adltc2990_config *cfg = dev->config;
428 	enum adltc2990_monitoring_type mode_v1_v2 = adltc2990_get_v1_v2_measurement_modes(
429 		cfg->measurement_mode[1], cfg->measurement_mode[0]);
430 	enum adltc2990_monitoring_type mode_v3_v4 = adltc2990_get_v3_v4_measurement_modes(
431 		cfg->measurement_mode[1], cfg->measurement_mode[0]);
432 
433 	uint8_t offset_index = 0, num_values_v1_v2 = 0, num_values_v3_v4 = 0;
434 
435 	switch (chan) {
436 	case SENSOR_CHAN_DIE_TEMP: {
437 		val->val1 = (data->internal_temperature) / 1000000;
438 		val->val2 = (data->internal_temperature) % 1000000;
439 		LOG_DBG("Internal Temperature Value is:%d.%d", val->val1, val->val2);
440 		break;
441 	}
442 	case SENSOR_CHAN_VOLTAGE: {
443 		if (mode_v1_v2 == VOLTAGE_SINGLEENDED) {
444 			LOG_DBG("Getting V1,V2");
445 			num_values_v1_v2 = ADLTC2990_VOLTAGE_SINGLE_ENDED_VALUES;
446 		} else if (mode_v1_v2 == VOLTAGE_DIFFERENTIAL) {
447 			LOG_DBG("Getting V3-V4");
448 			num_values_v1_v2 = ADLTC2990_VOLTAGE_DIFF_VALUES;
449 		}
450 		if (mode_v3_v4 == VOLTAGE_SINGLEENDED) {
451 			LOG_DBG("Getting V3,V4");
452 			num_values_v3_v4 = ADLTC2990_VOLTAGE_SINGLE_ENDED_VALUES;
453 		} else if (mode_v3_v4 == VOLTAGE_DIFFERENTIAL) {
454 			LOG_DBG("Getting V3-V4");
455 			num_values_v3_v4 = ADLTC2990_VOLTAGE_DIFF_VALUES;
456 		}
457 		/* Add VCC to the last index */
458 		val[num_values_v1_v2 + num_values_v3_v4].val1 = data->supply_voltage / 1000000;
459 		val[num_values_v1_v2 + num_values_v3_v4].val2 = data->supply_voltage % 1000000;
460 		break;
461 	}
462 	case SENSOR_CHAN_CURRENT: {
463 		if (!(mode_v1_v2 == VOLTAGE_DIFFERENTIAL || mode_v3_v4 == VOLTAGE_DIFFERENTIAL)) {
464 			LOG_ERR("Sensor is not configured to measure Current");
465 			return -EINVAL;
466 		}
467 		if (mode_v1_v2 == VOLTAGE_DIFFERENTIAL && mode_v3_v4 == VOLTAGE_DIFFERENTIAL) {
468 			LOG_DBG("Getting I12 and I34");
469 			num_values_v1_v2 = ADLTC2990_CURRENT_VALUES;
470 			num_values_v3_v4 = ADLTC2990_CURRENT_VALUES;
471 		} else if (mode_v1_v2 == VOLTAGE_DIFFERENTIAL) {
472 			LOG_DBG("Getting I12");
473 			num_values_v1_v2 = ADLTC2990_CURRENT_VALUES;
474 		} else if (mode_v3_v4 == VOLTAGE_DIFFERENTIAL) {
475 			LOG_DBG("Getting I34");
476 			num_values_v3_v4 = ADLTC2990_CURRENT_VALUES;
477 		}
478 		break;
479 	}
480 	case SENSOR_CHAN_AMBIENT_TEMP: {
481 		if (!(mode_v1_v2 == TEMPERATURE || mode_v3_v4 == TEMPERATURE)) {
482 			LOG_ERR("Sensor is not configured to measure Ambient Temperature");
483 			return -EINVAL;
484 		}
485 		if (mode_v1_v2 == TEMPERATURE && mode_v3_v4 == TEMPERATURE) {
486 			LOG_DBG("Getting T12 and T34");
487 			num_values_v1_v2 = ADLTC2990_TEMP_VALUES;
488 			num_values_v3_v4 = ADLTC2990_TEMP_VALUES;
489 		} else if (mode_v1_v2 == TEMPERATURE) {
490 			LOG_DBG("Getting T12");
491 			num_values_v1_v2 = ADLTC2990_TEMP_VALUES;
492 		} else if (mode_v3_v4 == TEMPERATURE) {
493 			LOG_DBG("Getting T34");
494 			num_values_v3_v4 = ADLTC2990_TEMP_VALUES;
495 		}
496 		break;
497 	}
498 	default: {
499 		return -ENOTSUP;
500 	}
501 	}
502 
503 	adltc2990_get_v1_v2_val(dev, val, num_values_v1_v2, &offset_index);
504 	adltc2990_get_v3_v4_val(dev, val, num_values_v3_v4, &offset_index);
505 	return 0;
506 }
507 
508 static DEVICE_API(sensor, adltc2990_driver_api) = {
509 	.sample_fetch = adltc2990_sample_fetch,
510 	.channel_get = adltc2990_channel_get,
511 };
512 
513 #define ADLTC2990_DEFINE(inst)                                                                     \
514 	static struct adltc2990_data adltc2990_data_##inst;                                        \
515 	static const struct adltc2990_config adltc2990_config_##inst = {                           \
516 		.bus = I2C_DT_SPEC_INST_GET(inst),                                                 \
517 		.temp_format = DT_INST_PROP(inst, temperature_format),                             \
518 		.acq_format = DT_INST_PROP(inst, acquistion_format),                               \
519 		.measurement_mode = DT_INST_PROP(inst, measurement_mode),                          \
520 		.pins_v1_v2.pins_current_resistor =                                                \
521 			DT_INST_PROP_OR(inst, pins_v1_v2_current_resistor, 1),                     \
522 		.pins_v1_v2.voltage_divider_resistors.v1_r1_r2 =                                   \
523 			DT_INST_PROP_OR(inst, pin_v1_voltage_divider_resistors, NULL),             \
524 		.pins_v1_v2.voltage_divider_resistors.v2_r1_r2 =                                   \
525 			DT_INST_PROP_OR(inst, pin_v2_voltage_divider_resistors, NULL),             \
526 		.pins_v3_v4.pins_current_resistor =                                                \
527 			DT_INST_PROP_OR(inst, pins_v3_v4_current_resistor, 1),                     \
528 		.pins_v3_v4.voltage_divider_resistors.v3_r1_r2 =                                   \
529 			DT_INST_PROP_OR(inst, pin_v3_voltage_divider_resistors, NULL),             \
530 		.pins_v3_v4.voltage_divider_resistors.v4_r1_r2 =                                   \
531 			DT_INST_PROP_OR(inst, pin_v4_voltage_divider_resistors, NULL)};            \
532                                                                                                    \
533 	SENSOR_DEVICE_DT_INST_DEFINE(inst, adltc2990_init, NULL, &adltc2990_data_##inst,           \
534 				     &adltc2990_config_##inst, POST_KERNEL,                        \
535 				     CONFIG_SENSOR_INIT_PRIORITY, &adltc2990_driver_api);
536 
537 DT_INST_FOREACH_STATUS_OKAY(ADLTC2990_DEFINE)
538