Lines Matching +full:micro +full:- +full:ohms
1 // SPDX-License-Identifier: GPL-2.0
33 *val *= rescale->numerator; in rescale_process_scale()
34 if (rescale->denominator == 1) in rescale_process_scale()
36 *val2 = rescale->denominator; in rescale_process_scale()
44 if (!check_mul_overflow(*val, rescale->numerator, &_val) && in rescale_process_scale()
45 !check_mul_overflow(*val2, rescale->denominator, &_val2)) { in rescale_process_scale()
53 tmp = div_s64(tmp, rescale->denominator); in rescale_process_scale()
54 tmp *= rescale->numerator; in rescale_process_scale()
80 * For IIO_VAL_INT_PLUS_{MICRO,NANO} scale types if either *val in rescale_process_scale()
82 * *val = 1 and *val2 = -0.5 yields -1.5 not -0.5. in rescale_process_scale()
86 tmp = (s64)abs(*val) * abs(rescale->numerator); in rescale_process_scale()
87 *val = div_s64_rem(tmp, abs(rescale->denominator), &rem); in rescale_process_scale()
89 tmp = (s64)rem * mult + (s64)abs(*val2) * abs(rescale->numerator); in rescale_process_scale()
90 tmp = div_s64(tmp, abs(rescale->denominator)); in rescale_process_scale()
98 if (neg ^ ((rescale->numerator < 0) ^ (rescale->denominator < 0))) { in rescale_process_scale()
100 *val = -*val; in rescale_process_scale()
102 *val2 = -*val2; in rescale_process_scale()
107 return -EOPNOTSUPP; in rescale_process_scale()
120 tmp = (s64)rescale->offset * scale2; in rescale_process_offset()
124 *val = div_s64(rescale->offset, scale) + schan_off; in rescale_process_offset()
127 tmp = (s64)rescale->offset * (1 << scale2); in rescale_process_offset()
131 tmp = (s64)rescale->offset * 1000000000LL; in rescale_process_offset()
136 tmp = (s64)rescale->offset * 1000000LL; in rescale_process_offset()
141 return -EOPNOTSUPP; in rescale_process_offset()
157 if (rescale->chan_processed) in rescale_read_raw()
163 return iio_read_channel_processed(rescale->source, val); in rescale_read_raw()
165 return iio_read_channel_raw(rescale->source, val); in rescale_read_raw()
168 if (rescale->chan_processed) { in rescale_read_raw()
170 * Processed channels are scaled 1-to-1 in rescale_read_raw()
176 ret = iio_read_channel_scale(rescale->source, val, val2); in rescale_read_raw()
181 * Processed channels are scaled 1-to-1 and source offset is in rescale_read_raw()
204 if (rescale->chan_processed) { in rescale_read_raw()
205 *val = rescale->offset; in rescale_read_raw()
209 if (iio_channel_has_info(rescale->source->channel, in rescale_read_raw()
211 ret = iio_read_channel_offset(rescale->source, in rescale_read_raw()
214 return ret < 0 ? ret : -EOPNOTSUPP; in rescale_read_raw()
217 ret = iio_read_channel_scale(rescale->source, &scale, &scale2); in rescale_read_raw()
221 return -EINVAL; in rescale_read_raw()
235 return iio_read_avail_channel_raw(rescale->source, in rescale_read_avail()
238 return -EINVAL; in rescale_read_avail()
254 return iio_read_channel_ext_info(rescale->source, in rescale_read_ext_info()
255 rescale->ext_info[private].name, in rescale_read_ext_info()
266 return iio_write_channel_ext_info(rescale->source, in rescale_write_ext_info()
267 rescale->ext_info[private].name, in rescale_write_ext_info()
274 struct iio_chan_spec *chan = &rescale->chan; in rescale_configure_channel()
275 struct iio_chan_spec const *schan = rescale->source->channel; in rescale_configure_channel()
277 chan->indexed = 1; in rescale_configure_channel()
278 chan->output = schan->output; in rescale_configure_channel()
279 chan->ext_info = rescale->ext_info; in rescale_configure_channel()
280 chan->type = rescale->cfg->type; in rescale_configure_channel()
287 rescale->chan_processed = true; in rescale_configure_channel()
290 return -EINVAL; in rescale_configure_channel()
293 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | in rescale_configure_channel()
296 if (rescale->offset) in rescale_configure_channel()
297 chan->info_mask_separate |= BIT(IIO_CHAN_INFO_OFFSET); in rescale_configure_channel()
305 !rescale->chan_processed) in rescale_configure_channel()
306 chan->info_mask_separate_available |= BIT(IIO_CHAN_INFO_RAW); in rescale_configure_channel()
320 ret = device_property_read_u32(dev, "sense-resistor-micro-ohms", in rescale_current_sense_amplifier_props()
327 device_property_read_u32(dev, "sense-gain-mult", &gain_mult); in rescale_current_sense_amplifier_props()
328 device_property_read_u32(dev, "sense-gain-div", &gain_div); in rescale_current_sense_amplifier_props()
336 rescale->numerator = 1000000 / factor; in rescale_current_sense_amplifier_props()
337 rescale->denominator = sense / factor; in rescale_current_sense_amplifier_props()
339 factor = gcd(rescale->numerator, gain_mult); in rescale_current_sense_amplifier_props()
340 rescale->numerator /= factor; in rescale_current_sense_amplifier_props()
341 rescale->denominator *= gain_mult / factor; in rescale_current_sense_amplifier_props()
343 factor = gcd(rescale->denominator, gain_div); in rescale_current_sense_amplifier_props()
344 rescale->numerator *= gain_div / factor; in rescale_current_sense_amplifier_props()
345 rescale->denominator /= factor; in rescale_current_sense_amplifier_props()
357 ret = device_property_read_u32(dev, "shunt-resistor-micro-ohms", in rescale_current_sense_shunt_props()
365 rescale->numerator = 1000000 / factor; in rescale_current_sense_shunt_props()
366 rescale->denominator = shunt / factor; in rescale_current_sense_shunt_props()
377 ret = device_property_read_u32(dev, "output-ohms", in rescale_voltage_divider_props()
378 &rescale->denominator); in rescale_voltage_divider_props()
380 dev_err(dev, "failed to read output-ohms: %d\n", ret); in rescale_voltage_divider_props()
384 ret = device_property_read_u32(dev, "full-ohms", in rescale_voltage_divider_props()
385 &rescale->numerator); in rescale_voltage_divider_props()
387 dev_err(dev, "failed to read full-ohms: %d\n", ret); in rescale_voltage_divider_props()
391 factor = gcd(rescale->numerator, rescale->denominator); in rescale_voltage_divider_props()
392 rescale->numerator /= factor; in rescale_voltage_divider_props()
393 rescale->denominator /= factor; in rescale_voltage_divider_props()
408 ret = device_property_read_u32(dev, "excitation-current-microamp", in rescale_temp_sense_rtd_props()
411 dev_err(dev, "failed to read excitation-current-microamp: %d\n", in rescale_temp_sense_rtd_props()
416 ret = device_property_read_u32(dev, "alpha-ppm-per-celsius", &alpha); in rescale_temp_sense_rtd_props()
418 dev_err(dev, "failed to read alpha-ppm-per-celsius: %d\n", in rescale_temp_sense_rtd_props()
423 ret = device_property_read_u32(dev, "r-naught-ohms", &r0); in rescale_temp_sense_rtd_props()
425 dev_err(dev, "failed to read r-naught-ohms: %d\n", ret); in rescale_temp_sense_rtd_props()
431 rescale->numerator = 1000000 / factor; in rescale_temp_sense_rtd_props()
432 rescale->denominator = tmp / factor; in rescale_temp_sense_rtd_props()
434 rescale->offset = -1 * ((r0 * iexc) / 1000); in rescale_temp_sense_rtd_props()
447 device_property_read_u32(dev, "sense-offset-millicelsius", &offset); in rescale_temp_transducer_props()
448 device_property_read_u32(dev, "sense-resistor-ohms", &sense); in rescale_temp_transducer_props()
449 ret = device_property_read_u32(dev, "alpha-ppm-per-celsius", &alpha); in rescale_temp_transducer_props()
451 dev_err(dev, "failed to read alpha-ppm-per-celsius: %d\n", ret); in rescale_temp_transducer_props()
455 rescale->numerator = 1000000; in rescale_temp_transducer_props()
456 rescale->denominator = alpha * sense; in rescale_temp_transducer_props()
458 rescale->offset = div_s64((s64)offset * rescale->denominator, in rescale_temp_transducer_props()
459 rescale->numerator); in rescale_temp_transducer_props()
496 { .compatible = "current-sense-amplifier",
498 { .compatible = "current-sense-shunt",
500 { .compatible = "voltage-divider",
502 { .compatible = "temperature-sense-rtd",
504 { .compatible = "temperature-transducer",
512 struct device *dev = &pdev->dev; in rescale_probe()
529 sizeof_ext_info *= sizeof(*rescale->ext_info); in rescale_probe()
536 return -ENOMEM; in rescale_probe()
540 rescale->cfg = device_get_match_data(dev); in rescale_probe()
541 rescale->numerator = 1; in rescale_probe()
542 rescale->denominator = 1; in rescale_probe()
543 rescale->offset = 0; in rescale_probe()
545 ret = rescale->cfg->props(dev, rescale); in rescale_probe()
549 if (!rescale->numerator || !rescale->denominator) { in rescale_probe()
551 return -EINVAL; in rescale_probe()
556 rescale->source = source; in rescale_probe()
558 indio_dev->name = dev_name(dev); in rescale_probe()
559 indio_dev->info = &rescale_info; in rescale_probe()
560 indio_dev->modes = INDIO_DIRECT_MODE; in rescale_probe()
561 indio_dev->channels = &rescale->chan; in rescale_probe()
562 indio_dev->num_channels = 1; in rescale_probe()
564 rescale->ext_info = devm_kmemdup(dev, in rescale_probe()
565 source->channel->ext_info, in rescale_probe()
567 if (!rescale->ext_info) in rescale_probe()
568 return -ENOMEM; in rescale_probe()
570 for (i = 0; rescale->ext_info[i].name; ++i) { in rescale_probe()
572 &rescale->ext_info[i]; in rescale_probe()
574 if (source->channel->ext_info[i].read) in rescale_probe()
575 ext_info->read = rescale_read_ext_info; in rescale_probe()
576 if (source->channel->ext_info[i].write) in rescale_probe()
577 ext_info->write = rescale_write_ext_info; in rescale_probe()
578 ext_info->private = i; in rescale_probe()
592 .name = "iio-rescale",