drivers/iio/afe/iio-rescale.c
Source file repositories/reference/linux-study-clean/drivers/iio/afe/iio-rescale.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/afe/iio-rescale.c- Extension
.c- Size
- 15712 bytes
- Lines
- 612
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/err.hlinux/gcd.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/iio/afe/rescale.hlinux/iio/consumer.hlinux/iio/iio.h
Detected Declarations
enum rescale_variantfunction Copyrightfunction lossfunction rescale_process_offsetfunction rescale_read_rawfunction rescale_read_availfunction rescale_read_ext_infofunction rescale_write_ext_infofunction rescale_configure_channelfunction rescale_current_sense_amplifier_propsfunction rescale_current_sense_shunt_propsfunction rescale_voltage_divider_propsfunction rescale_temp_sense_rtd_propsfunction rescale_temp_transducer_propsfunction rescale_probe
Annotated Snippet
if (neg ^ ((rescale->numerator < 0) ^ (rescale->denominator < 0))) {
if (*val)
*val = -*val;
else
*val2 = -*val2;
}
return scale_type;
default:
return -EOPNOTSUPP;
}
}
EXPORT_SYMBOL_NS_GPL(rescale_process_scale, "IIO_RESCALE");
int rescale_process_offset(struct rescale *rescale, int scale_type,
int scale, int scale2, int schan_off,
int *val, int *val2)
{
s64 tmp, tmp2;
switch (scale_type) {
case IIO_VAL_FRACTIONAL:
tmp = (s64)rescale->offset * scale2;
*val = div_s64(tmp, scale) + schan_off;
return IIO_VAL_INT;
case IIO_VAL_INT:
*val = div_s64(rescale->offset, scale) + schan_off;
return IIO_VAL_INT;
case IIO_VAL_FRACTIONAL_LOG2:
tmp = (s64)rescale->offset * (1 << scale2);
*val = div_s64(tmp, scale) + schan_off;
return IIO_VAL_INT;
case IIO_VAL_INT_PLUS_NANO:
tmp = (s64)rescale->offset * 1000000000LL;
tmp2 = ((s64)scale * 1000000000LL) + scale2;
*val = div64_s64(tmp, tmp2) + schan_off;
return IIO_VAL_INT;
case IIO_VAL_INT_PLUS_MICRO:
tmp = (s64)rescale->offset * 1000000LL;
tmp2 = ((s64)scale * 1000000LL) + scale2;
*val = div64_s64(tmp, tmp2) + schan_off;
return IIO_VAL_INT;
default:
return -EOPNOTSUPP;
}
}
EXPORT_SYMBOL_NS_GPL(rescale_process_offset, "IIO_RESCALE");
static int rescale_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct rescale *rescale = iio_priv(indio_dev);
int scale, scale2;
int schan_off = 0;
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
if (rescale->chan_processed)
/*
* When only processed channels are supported, we
* read the processed data and scale it by 1/1
* augmented with whatever the rescaler has calculated.
*/
return iio_read_channel_processed(rescale->source, val);
else
return iio_read_channel_raw(rescale->source, val);
case IIO_CHAN_INFO_SCALE:
if (rescale->chan_processed) {
/*
* Processed channels are scaled 1-to-1
*/
*val = 1;
*val2 = 1;
ret = IIO_VAL_FRACTIONAL;
} else {
ret = iio_read_channel_scale(rescale->source, val, val2);
}
return rescale_process_scale(rescale, ret, val, val2);
case IIO_CHAN_INFO_OFFSET:
/*
* Processed channels are scaled 1-to-1 and source offset is
* already taken into account.
*
* In other cases, real world measurement are expressed as:
*
* schan_scale * (raw + schan_offset)
*
Annotation
- Immediate include surface: `linux/err.h`, `linux/gcd.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`, `linux/property.h`, `linux/iio/afe/rescale.h`, `linux/iio/consumer.h`.
- Detected declarations: `enum rescale_variant`, `function Copyright`, `function loss`, `function rescale_process_offset`, `function rescale_read_raw`, `function rescale_read_avail`, `function rescale_read_ext_info`, `function rescale_write_ext_info`, `function rescale_configure_channel`, `function rescale_current_sense_amplifier_props`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.