Lines Matching refs:rescale
20 struct rescale;
24 int (*props)(struct device *dev, struct rescale *rescale);
27 struct rescale { struct
41 struct rescale *rescale = iio_priv(indio_dev); in rescale_read_raw() argument
47 if (rescale->chan_processed) in rescale_read_raw()
53 return iio_read_channel_processed(rescale->source, val); in rescale_read_raw()
55 return iio_read_channel_raw(rescale->source, val); in rescale_read_raw()
58 if (rescale->chan_processed) { in rescale_read_raw()
66 ret = iio_read_channel_scale(rescale->source, val, val2); in rescale_read_raw()
70 *val *= rescale->numerator; in rescale_read_raw()
71 *val2 *= rescale->denominator; in rescale_read_raw()
74 *val *= rescale->numerator; in rescale_read_raw()
75 if (rescale->denominator == 1) in rescale_read_raw()
77 *val2 = rescale->denominator; in rescale_read_raw()
81 do_div(tmp, rescale->denominator); in rescale_read_raw()
82 tmp *= rescale->numerator; in rescale_read_raw()
99 struct rescale *rescale = iio_priv(indio_dev); in rescale_read_avail() local
104 return iio_read_avail_channel_raw(rescale->source, in rescale_read_avail()
121 struct rescale *rescale = iio_priv(indio_dev); in rescale_read_ext_info() local
123 return iio_read_channel_ext_info(rescale->source, in rescale_read_ext_info()
124 rescale->ext_info[private].name, in rescale_read_ext_info()
133 struct rescale *rescale = iio_priv(indio_dev); in rescale_write_ext_info() local
135 return iio_write_channel_ext_info(rescale->source, in rescale_write_ext_info()
136 rescale->ext_info[private].name, in rescale_write_ext_info()
141 struct rescale *rescale) in rescale_configure_channel() argument
143 struct iio_chan_spec *chan = &rescale->chan; in rescale_configure_channel()
144 struct iio_chan_spec const *schan = rescale->source->channel; in rescale_configure_channel()
148 chan->ext_info = rescale->ext_info; in rescale_configure_channel()
149 chan->type = rescale->cfg->type; in rescale_configure_channel()
156 rescale->chan_processed = true; in rescale_configure_channel()
171 !rescale->chan_processed) in rescale_configure_channel()
178 struct rescale *rescale) in rescale_current_sense_amplifier_props() argument
202 rescale->numerator = 1000000 / factor; in rescale_current_sense_amplifier_props()
203 rescale->denominator = sense / factor; in rescale_current_sense_amplifier_props()
205 factor = gcd(rescale->numerator, gain_mult); in rescale_current_sense_amplifier_props()
206 rescale->numerator /= factor; in rescale_current_sense_amplifier_props()
207 rescale->denominator *= gain_mult / factor; in rescale_current_sense_amplifier_props()
209 factor = gcd(rescale->denominator, gain_div); in rescale_current_sense_amplifier_props()
210 rescale->numerator *= gain_div / factor; in rescale_current_sense_amplifier_props()
211 rescale->denominator /= factor; in rescale_current_sense_amplifier_props()
217 struct rescale *rescale) in rescale_current_sense_shunt_props() argument
231 rescale->numerator = 1000000 / factor; in rescale_current_sense_shunt_props()
232 rescale->denominator = shunt / factor; in rescale_current_sense_shunt_props()
238 struct rescale *rescale) in rescale_voltage_divider_props() argument
244 &rescale->denominator); in rescale_voltage_divider_props()
251 &rescale->numerator); in rescale_voltage_divider_props()
257 factor = gcd(rescale->numerator, rescale->denominator); in rescale_voltage_divider_props()
258 rescale->numerator /= factor; in rescale_voltage_divider_props()
259 rescale->denominator /= factor; in rescale_voltage_divider_props()
301 struct rescale *rescale; in rescale_probe() local
315 sizeof_ext_info *= sizeof(*rescale->ext_info); in rescale_probe()
318 sizeof_priv = sizeof(*rescale) + sizeof_ext_info; in rescale_probe()
324 rescale = iio_priv(indio_dev); in rescale_probe()
326 rescale->cfg = of_device_get_match_data(dev); in rescale_probe()
327 rescale->numerator = 1; in rescale_probe()
328 rescale->denominator = 1; in rescale_probe()
330 ret = rescale->cfg->props(dev, rescale); in rescale_probe()
334 if (!rescale->numerator || !rescale->denominator) { in rescale_probe()
341 rescale->source = source; in rescale_probe()
346 indio_dev->channels = &rescale->chan; in rescale_probe()
349 rescale->ext_info = devm_kmemdup(dev, in rescale_probe()
352 if (!rescale->ext_info) in rescale_probe()
355 for (i = 0; rescale->ext_info[i].name; ++i) { in rescale_probe()
357 &rescale->ext_info[i]; in rescale_probe()
367 ret = rescale_configure_channel(dev, rescale); in rescale_probe()