Lines Matching +full:shunt +full:- +full:resistor +full:- +full:micro +full:- +full:ohms

1 // SPDX-License-Identifier: GPL-2.0
46 return iio_read_channel_raw(rescale->source, val); in rescale_read_raw()
49 ret = iio_read_channel_scale(rescale->source, val, val2); in rescale_read_raw()
52 *val *= rescale->numerator; in rescale_read_raw()
53 *val2 *= rescale->denominator; in rescale_read_raw()
56 *val *= rescale->numerator; in rescale_read_raw()
57 if (rescale->denominator == 1) in rescale_read_raw()
59 *val2 = rescale->denominator; in rescale_read_raw()
63 do_div(tmp, rescale->denominator); in rescale_read_raw()
64 tmp *= rescale->numerator; in rescale_read_raw()
69 return -EOPNOTSUPP; in rescale_read_raw()
72 return -EINVAL; in rescale_read_raw()
86 return iio_read_avail_channel_raw(rescale->source, in rescale_read_avail()
89 return -EINVAL; in rescale_read_avail()
105 return iio_read_channel_ext_info(rescale->source, in rescale_read_ext_info()
106 rescale->ext_info[private].name, in rescale_read_ext_info()
117 return iio_write_channel_ext_info(rescale->source, in rescale_write_ext_info()
118 rescale->ext_info[private].name, in rescale_write_ext_info()
125 struct iio_chan_spec *chan = &rescale->chan; in rescale_configure_channel()
126 struct iio_chan_spec const *schan = rescale->source->channel; in rescale_configure_channel()
128 chan->indexed = 1; in rescale_configure_channel()
129 chan->output = schan->output; in rescale_configure_channel()
130 chan->ext_info = rescale->ext_info; in rescale_configure_channel()
131 chan->type = rescale->cfg->type; in rescale_configure_channel()
136 return -EINVAL; in rescale_configure_channel()
139 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | in rescale_configure_channel()
143 chan->info_mask_separate_available |= BIT(IIO_CHAN_INFO_RAW); in rescale_configure_channel()
157 ret = device_property_read_u32(dev, "sense-resistor-micro-ohms", in rescale_current_sense_amplifier_props()
164 device_property_read_u32(dev, "sense-gain-mult", &gain_mult); in rescale_current_sense_amplifier_props()
165 device_property_read_u32(dev, "sense-gain-div", &gain_div); in rescale_current_sense_amplifier_props()
173 rescale->numerator = 1000000 / factor; in rescale_current_sense_amplifier_props()
174 rescale->denominator = sense / factor; in rescale_current_sense_amplifier_props()
176 factor = gcd(rescale->numerator, gain_mult); in rescale_current_sense_amplifier_props()
177 rescale->numerator /= factor; in rescale_current_sense_amplifier_props()
178 rescale->denominator *= gain_mult / factor; in rescale_current_sense_amplifier_props()
180 factor = gcd(rescale->denominator, gain_div); in rescale_current_sense_amplifier_props()
181 rescale->numerator *= gain_div / factor; in rescale_current_sense_amplifier_props()
182 rescale->denominator /= factor; in rescale_current_sense_amplifier_props()
190 u32 shunt; in rescale_current_sense_shunt_props() local
194 ret = device_property_read_u32(dev, "shunt-resistor-micro-ohms", in rescale_current_sense_shunt_props()
195 &shunt); in rescale_current_sense_shunt_props()
197 dev_err(dev, "failed to read the shunt resistance: %d\n", ret); in rescale_current_sense_shunt_props()
201 factor = gcd(shunt, 1000000); in rescale_current_sense_shunt_props()
202 rescale->numerator = 1000000 / factor; in rescale_current_sense_shunt_props()
203 rescale->denominator = shunt / factor; in rescale_current_sense_shunt_props()
214 ret = device_property_read_u32(dev, "output-ohms", in rescale_voltage_divider_props()
215 &rescale->denominator); in rescale_voltage_divider_props()
217 dev_err(dev, "failed to read output-ohms: %d\n", ret); in rescale_voltage_divider_props()
221 ret = device_property_read_u32(dev, "full-ohms", in rescale_voltage_divider_props()
222 &rescale->numerator); in rescale_voltage_divider_props()
224 dev_err(dev, "failed to read full-ohms: %d\n", ret); in rescale_voltage_divider_props()
228 factor = gcd(rescale->numerator, rescale->denominator); in rescale_voltage_divider_props()
229 rescale->numerator /= factor; in rescale_voltage_divider_props()
230 rescale->denominator /= factor; in rescale_voltage_divider_props()
257 { .compatible = "current-sense-amplifier",
259 { .compatible = "current-sense-shunt",
261 { .compatible = "voltage-divider",
269 struct device *dev = &pdev->dev; in rescale_probe()
286 sizeof_ext_info *= sizeof(*rescale->ext_info); in rescale_probe()
293 return -ENOMEM; in rescale_probe()
297 rescale->cfg = of_device_get_match_data(dev); in rescale_probe()
298 rescale->numerator = 1; in rescale_probe()
299 rescale->denominator = 1; in rescale_probe()
301 ret = rescale->cfg->props(dev, rescale); in rescale_probe()
305 if (!rescale->numerator || !rescale->denominator) { in rescale_probe()
307 return -EINVAL; in rescale_probe()
312 rescale->source = source; in rescale_probe()
314 indio_dev->name = dev_name(dev); in rescale_probe()
315 indio_dev->info = &rescale_info; in rescale_probe()
316 indio_dev->modes = INDIO_DIRECT_MODE; in rescale_probe()
317 indio_dev->channels = &rescale->chan; in rescale_probe()
318 indio_dev->num_channels = 1; in rescale_probe()
320 rescale->ext_info = devm_kmemdup(dev, in rescale_probe()
321 source->channel->ext_info, in rescale_probe()
323 if (!rescale->ext_info) in rescale_probe()
324 return -ENOMEM; in rescale_probe()
326 for (i = 0; rescale->ext_info[i].name; ++i) { in rescale_probe()
328 &rescale->ext_info[i]; in rescale_probe()
330 if (source->channel->ext_info[i].read) in rescale_probe()
331 ext_info->read = rescale_read_ext_info; in rescale_probe()
332 if (source->channel->ext_info[i].write) in rescale_probe()
333 ext_info->write = rescale_write_ext_info; in rescale_probe()
334 ext_info->private = i; in rescale_probe()
348 .name = "iio-rescale",