Re: [PATCH v4 2/2] dt-bindings: iio: filter: Add lpf/hpf freq margins

Sam Winchenbach
2025-03-03T13:31:40Z

On Mon, Mar 03, 2025 at 09:13:00AM +0100, Krzysztof Kozlowski wrote:
> On 26/02/2025 23:16, Sam Winchenbach wrote:
> >>>>> + adi,hpf-margin-hz:
> >>>>> + description:
> >>>>> + Sets maximum high-pass corner frequency to the frequency of rf_in minus
> >>>>> + this value when in auto mode.
> >>>>
> >>>> IIUC, these are two bounds - lower and upper - in relation to something
> >>>> else (like rf_in frequency)? If so, make it an array (naming to be
> >>>> discuss, I assume you know better what's that):
> >>>
> >>> It is true that these are both related to rf_in but both the low and high pass
> >>> filters can operate independently. Logically, IMO, it makes more sense to have
> >>
> >>
> >> You mean you can set only low or high pass and keep other as default?
> >> But what is the default then - something from reset value or "0" means
> >> disabled?
> >
> > This value isn't setting the corner frequency of the filter, but the minimum
> > distance the corner must be from the fundamental frequency. So, for example,
> > if rf_in is 3.35 GHz and you set lpf-margin-hz to 0 then the corner frequency
> > will be set to 3.35 GHz because that is an exact value supported by the device.
> >
> > If lpf-margin-hz is set to 30 MHz (for example), then corner frequency would be
> > at least 3.35 GHz + 30 MHz = 3.38 GHz. 3.49 GHz is the closest corner
> > frequency without going below 3.38 GHz that is supported by the device, so that
> > is what will be selected.
> >
> > This prevents the situation where your fundamental frequency falls on, or close
> > to, a corner frequency which could result in 3dB (half power) loss in your
> > signal.
> >
> > This is all completely indepent of the high-pass filter.
>
> Description is confusing a bit, because it suggests the value sets the
> corner frequency. It explicitly says this - "sets ... corner frequency"
> and such meaning for properties we usually associate with the property
> doing this. Here however corner frequency will be always set to rf_in
> and you just adjust the value.
>

How about: "Sets the minimum distance (in Hz) between the fundamental
frequency of `rf_in` and the corner frequency of the high-pass, input filter
when operatred in 'auto' mode. The selected high-pass corner frequency will
be less than, or equal to, `rf_in` - `hpf-margin-hz`. If not setting is found
that satisfies this relationship the filter will be put into 'bypass'."

Perhaps that is a bit more clear on the intention of this parameter?

> >
> >>
> >>> them as separate controls but I am happy to put them into an array if that is
> >>> the idiomatic approach to situations like this. That said, I am having a
> >>> difficult time getting dt_binding_check to pass when I have an array of uint64.
> >>>
> >>> When listing two items, as in your example below, I get the following:
> >>> adi,admv8818.example.dtb: admv8818@0: adi,filter-margins-hz: [[0, 30000000], [0, 30000000]] is too long
> >>
> >> Tricky to say without seeing your code. Magic crystal ball had
> >> malfunction today.
> >
> > This is the property:
> >
> > adi,filter-margins-hz:
> > items:
> > - description: |
> > The minimum distance, in Hz, between rf_in and the low-pass corner
> > frequency when the device is used in "auto" mode. If the sum of
> > rf_in and this value is greater than 18.85 GHz then the low-pass
> > filter will be put into bypass mode, otherwise the closest corner
> > frequency that is greater than or equal to the sum of rf_in plus this
> > value will be used.
> > minimum: 0
> > maximum: 0xFFFFFFFFFFFFFFFF
> > default: 0
> > - description: |
> > The minimum distance, in Hz, between rf_in and the high-pass corner
> > frequency when the device is used in "auto" mode. If the difference
> > between rf_in and this value is less than 1.75 GHz then the high-pass
> > filter will be put into bypass mode, otherwise the closest corner
> > frequency that is less than or equal to the difference of rf_in and
> > this value will be used.
> > minimum: 0
> > maximum: 0xFFFFFFFFFFFFFFFF
> > default: 0
> >
> > And this is the example:
> >
> > examples:
> > - |
> > spi {
> > #address-cells = <1>;
> > #size-cells = <0>;
> > admv8818@0 {
> > compatible = "adi,admv8818";
> > reg = <0>;
> > spi-max-frequency = <10000000>;
> > clocks = <&admv8818_rfin>;
> > clock-names = "rf_in";
> > adi,filter-margins-hz = /bits/ 64 <30000000 30000000>;
>
>
> foo-hz is in 32-bit, so basically you have here 4 32-bit numbers which
> indeed reported by dtschema - property is too long. Drop 64-bit here.
>

I was hoping to keep this 64 bits seeing this is a 18 GHz+ filter. I suppose
I could change this to MHz and just lose a bit of resolution. Does that sound
like a better approach?

> Device allows multiple LPF/HPF values to be stored in LUT tables and it
> actually has four independent filters. Shouldn't these be included here?
> Maybe not LUT tables, but the configuration for all filters?
>

There are two filters, the input (high-pass) filter, and the output (low-pass)
filter. Each filter has four banks, each with a different range of frequencies.
Only one bank can be selected at a time. Each bank has 16 different possible
cutoff/corner frequencies. That is a total of 64 distinct values for each of
the two filters.

The issue with setting the corner frequency directly is that in certain
applications (such as software defined radios) the fundamental frequency
is adjustable, necessitating that the corner frequencies of the filter are
adjusted accordingly. When the filter is in "auto" mode it is notified via
the clock system of frequency changes, so using this information it should be
possible to select new corner frequencies if you know the minimum distance
between your fundamental frequency and the corner.

It is possible there is either not enough call for this feature, or it goes
against the designs of the maintainters. If that is the case we should decline
this patch and we will maintain it in our fork of the kernel.

Thanks,
-Sam

> Best regards,
> Krzysztof