You can configure the MCA ADC lines to act as an analog window comparator and generate an IRQ depending on the voltage level in the input. This feature allows applications to be notified of this event instead of needing to periodically poll the input for its value.

Since this is an extension on the ADC driver, reading the input is also possible by using the same sysfs entry. The same formulas, channel mapping, and voltage reference also apply.

The comparator can be seen as a digital output that depends on two limits or thresholds: when the input is between the two limits the comparator’s output will be 1, and 0 when it is outside of the limits. If only one limit is needed, then the higher threshold should be set above the maximum (4096) and use the lower one.

The image below helps to understand when the edges are generated, basically, entering the window will generate a rising edge and leaving it will generate a falling one, regardless from which threshold was exceeded (upper or lower). This means that it is likely to be necessary an extra read to the analog input to determine in which of the two zones outside the window the voltage is.

dwg mca analog comparator

Device tree bindings and customization

The MCA ADC device tree binding is documented at Documentation/devicetree/bindings/iio/adc/digi,mca-adc.txt.

You can specify the list of channels you want to use as comparators with property digi,comparator-ch-list.

Both adc-ch-list and comparator-ch-list properties are exclusive. If a channel is mistakenly included in both, adc-ch-list has priority and the kernel logs a warning.

MCA-enabled ADC channels and voltage reference

This example shows how to enable the analog comparator on one MCA ADC channel using the property digi,comparator-ch-list. Rest of ADC channels are used as normal ADC channels. The voltage reference property is the same for both ADCs and Comparators, refer to the ADC configuration chapter for more details on how to configure this property.

ConnectCore 8M Mini Development Kit device tree
&mca_adc {
	digi,adc-ch-list = <1 2 4>;
	digi,comparator-ch-list = <3>;
	digi,adc-vref = <3000000>;
};