iio: frequency: add iio support for Amlogic clock measure
Jerome Brunet
reviewercover iio: frequency: add iio support for Amlogic clock measure
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found in drivers/soc/amlogic/meson-clk-measure.c with following improvements:
* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurements
Jerome Brunet (2):
dt-bindings: iio: frequency: add clock measure support
iio: frequency: add amlogic clock measure support
.../iio/frequency/amlogic,clk-msr-io.yaml | 50 ++ drivers/iio/frequency/Kconfig | 15 + drivers/iio/frequency/Makefile | 1 + drivers/iio/frequency/amlogic-clk-msr-io.c | 802 ++++++++++++++++++ 4 files changed, 868 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/frequency/amlogic,clk-msr-io.yaml create mode 100644 drivers/iio/frequency/amlogic-clk-msr-io.c
Signature · 1 line
2.43.0
Jerome Brunet
reviewerPATCH 1/2 dt-bindings: iio: frequency: add clock measure support
Introduce new bindings for the clock measure IP found Amlogic SoCs. These new bindings help bring IIO support to AML clock measure.
---
NOTE:
#1: Splitting the register space looks odd. This is done to help support
future SoCs. From meson8 to sm1, duty register comes first, then the reg space. On s4 and c3, duty comes after the reg space.
#2: 'reg' may look like a poor choice of name. This comes from the
documentation.
- MSR_CLK_REGx for the 'reg' space (x being a number)
- MSR_CLK_DUTY for the 'duty' space
.../iio/frequency/amlogic,clk-msr-io.yaml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/frequency/amlogic,clk-msr-io.yaml
Documentation/devicetree/bindings/iio/frequency/amlogic,clk-msr-io.yaml new file +50 -0
@@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/frequency/amlogic,clk-msr-io.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Amlogic System Clock Measurer + +description: + Internal clock rate sensor within Amlogic SoCs + +maintainers: + - Neil Armstrong <[email protected]> + +properties: + compatible: + enum: + - amlogic,meson8-clk-msr-io + - amlogic,gx-clk-msr-io + - amlogic,axg-clk-msr-io + - amlogic,g12a-clk-msr-io + - amlogic,sm1-clk-msr-io + + reg: + maxItems: 2 + + reg-names: + items: + - const: reg + - const: duty + + "#io-channel-cells": + const: 1 + +required: + - compatible + - reg + - reg-names + +unevaluatedProperties: false + +examples: + - | + clk_msr: rate-sensor@18000 { + compatible = "amlogic,axg-clk-msr-io"; + reg = <0x18004 0xc>, + <0x18000 0x4>; + reg-names = "reg", "duty"; + #io-channel-cells = <1>; + };
Signature · 1 line
2.43.0
Re: [PATCH 1/2] dt-bindings: iio: frequency: add clock measure support
Quoted 4 lines · Jerome Brunet
Introduce new bindings for the clock measure IP found Amlogic SoCs. These new bindings help bring IIO support to AML clock measure.
Signed-off-by Jerome Brunet <[email protected]>
<form letter>
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.
Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline), work on fork of kernel (don't, instead use mainline) or you ignore some maintainers (really don't). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.
You missed at least devicetree list (maybe more), so this won't be tested by automated tooling.
Please kindly resend and include all necessary To/Cc entries. </form letter>
Best regards,
Krzysztof
Jerome Brunet
reviewerPATCH 2/2 iio: frequency: add amlogic clock measure support
In reply to Jerome BrunetAdd support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found in drivers/soc/amlogic/meson-clk-measure.c with following improvements:
* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurements
--- drivers/iio/frequency/Kconfig | 15 + drivers/iio/frequency/Makefile | 1 + drivers/iio/frequency/amlogic-clk-msr-io.c | 802 +++++++++++++++++++++ 3 files changed, 818 insertions(+) create mode 100644 drivers/iio/frequency/amlogic-clk-msr-io.c
drivers/iio/frequency/Kconfig +15 -0
@@ -7,6 +7,21 @@ # # When adding new entries keep the list in alphabetical order +menu "Frequency Measurements" + +config AMLOGIC_CLK_MSR_IO + tristate "Amlogic IO Clock Measure" + default ARCH_MESON + depends on REGMAP_MMIO && COMMON_CLK + help + Say yes here to build support for Amlogic Clock Measure + HW found in Amlogic SoC, with IIO support + + To compile this driver as a module, choose M here: the + module will be called amlogic-clk-msr-io. + +endmenu + menu "Frequency Synthesizers DDS/PLL" menu "Clock Generator/Distribution"
drivers/iio/frequency/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-$(CONFIG_ADMV1013) += admv1013.o obj-$(CONFIG_ADMV1014) += admv1014.o obj-$(CONFIG_ADMV4420) += admv4420.o obj-$(CONFIG_ADRF6780) += adrf6780.o +obj-$(CONFIG_AMLOGIC_CLK_MSR_IO) += amlogic-clk-msr-io.o
drivers/iio/frequency/amlogic-clk-msr-io.c new file +802 -0
802 lines not on this page · raw message
Signature · 1 line
2.43.0
David Lechner
reviewerRe: [PATCH 2/2] iio: frequency: add amlogic clock measure support
Quoted 7 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
drivers/iio/frequency/amlogic-clk-msr-io.c new file +1
-0+static int cmsr_read_raw(struct iio_dev *indio_dev,
drivers/iio/frequency/amlogic-clk-msr-io.c line 642
Quoted 10 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +10
-0+struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct amlogic_cmsr *cm = iio_priv(indio_dev); + +guard (mutex)(&cm->lock); + +switch (mask) { +case IIO_CHAN_INFO_RAW : + *val =cmsr_measure_unlocked (cm, chan->channel);
Is this actually returning an alternating voltage magnitutde? Most frequency drivers don't have a raw value, only frequency.
drivers/iio/frequency/amlogic-clk-msr-io.c line 647
Quoted 5 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +5
-0+if (*val <0 ) +return *val; +return IIO_VAL_INT ; + +case IIO_CHAN_INFO_PROCESSED :/* Result in Hz */
Shouldn't this be IIO_CHAN_INFO_FREQUENCY?
Processed is just (raw + offset) * scale which would be a voltage in this case since the channel type is IIO_ALTVOLTAGE.
drivers/iio/frequency/amlogic-clk-msr-io.c line 653
Quoted 6 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +6
-0+ *val =cmsr_measure_processed_unlocked (cm, chan->channel, val2); +if (*val <0 ) +return *val; +return IIO_VAL_INT_64 ; + +case IIO_CHAN_INFO_SCALE :
What is this attribute being used for?
(clearly not used to convert the raw value to millivolts :-) )
Maybe IIO_CHAN_INFO_INT_TIME is the right one for this? Although so far, that has only been used with light sensors.
Quoted 9 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +9
-0+ *val2 =cmsr_get_time_unlocked (cm); + *val =1000000 ; +return IIO_VAL_FRACTIONAL ; + +default : +return -EINVAL ; + } +} +
David Lechner
reviewerRe: [PATCH 2/2] iio: frequency: add amlogic clock measure support
Quoted 42 lines · David Lechner
Quoted 7 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
drivers/iio/frequency/amlogic-clk-msr-io.c new file +1
-0+static int cmsr_read_raw(struct iio_dev *indio_dev,drivers/iio/frequency/amlogic-clk-msr-io.c line 642
Quoted 10 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +10
-0+struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct amlogic_cmsr *cm = iio_priv(indio_dev); + +guard (mutex)(&cm->lock); + +switch (mask) { +case IIO_CHAN_INFO_RAW : + *val =cmsr_measure_unlocked (cm, chan->channel);Is this actually returning an alternating voltage magnitutde? Most frequency drivers don't have a raw value, only frequency.
drivers/iio/frequency/amlogic-clk-msr-io.c line 647
Quoted 5 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +5
-0+if (*val <0 ) +return *val; +return IIO_VAL_INT ; + +case IIO_CHAN_INFO_PROCESSED :/* Result in Hz */ Shouldn't this be
IIO_CHAN_INFO_FREQUENCY?Processed is just (raw + offset) * scale which would be a voltage in this case since the channel type is
IIO_ALTVOLTAGE.drivers/iio/frequency/amlogic-clk-msr-io.c line 653
Quoted 6 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +6
-0+ *val =cmsr_measure_processed_unlocked (cm, chan->channel, val2); +if (*val <0 ) +return *val; +return IIO_VAL_INT_64 ; + +case IIO_CHAN_INFO_SCALE :What is this attribute being used for?
Quoted 4 lines
(clearly not used to convert the raw value to millivolts :-) )
Maybe
IIO_CHAN_INFO_INT_TIMEis the right one for this? Although so far, that has only been used with light sensors.
Probably not the right idea though since it applies to the frequency measurement, not the voltage measurement.
Quoted 10 lines
Quoted 10 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +9
-0+ *val2 =cmsr_get_time_unlocked (cm); + *val =1000000 ; +return IIO_VAL_FRACTIONAL ; + +default : +return -EINVAL ; + } +} +
Jerome Brunet
reviewerRe: [PATCH 2/2] iio: frequency: add amlogic clock measure support
In reply to David LechnerQuoted 7 lines · David Lechner
Quoted 3 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
Quoted 14 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 642
Quoted 11 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +11
-0+static int cmsr_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct amlogic_cmsr *cm =iio_priv (indio_dev); + +guard (mutex)(&cm->lock); + +switch (mask) { +case IIO_CHAN_INFO_RAW : + *val =cmsr_measure_unlocked (cm, chan->channel);Is this actually returning an alternating voltage magnitutde? Most frequency drivers don't have a raw value, only frequency.
No it is not the magnitude, it is the clock rate (frequency) indeed. Maybe altvoltage was not the right pick for that but nothing obvious stands out for Hz measurements
Quoted 8 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 647
Quoted 6 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +5
-0+if (*val <0 ) +return *val; +return IIO_VAL_INT ; + +case IIO_CHAN_INFO_PROCESSED :/* Result in Hz */ Shouldn't this be
IIO_CHAN_INFO_FREQUENCY?
How would I get raw / processed / scale with IIO_CHAN_INFO_FREQUENCY ?
Quoted 3 lines
Processed is just (raw + offset) * scale which would be a voltage in this case since the channel type is
IIO_ALTVOLTAGE.
This is was Processed does here, along with selecting the most appropriate scale to perform the measurement.
Quoted 9 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 653
Quoted 7 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +6
-0+ *val =cmsr_measure_processed_unlocked (cm, chan->channel, val2); +if (*val <0 ) +return *val; +return IIO_VAL_INT_64 ; + +case IIO_CHAN_INFO_SCALE :What is this attribute being used for?
Hz
Quoted 5 lines
(clearly not used to convert the raw value to millivolts :-) )
Maybe
IIO_CHAN_INFO_INT_TIMEis the right one for this? Although so far, that has only been used with light sensors.
I think you are mixing up channel info and type here. I do want the info
* IIO_CHAN_INFO_RAW
* IIO_CHAN_INFO_PROCESSED
* IIO_CHAN_INFO_SCALE
I want those info to represent an alternate voltage frequency in Hz. I thought type 'IIO_ALTVOLTAGE' was the right pick for that. Apparently it is not. What is the appropriate type then ? Should I add a new one ?
Quoted 10 lines
Quoted 10 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +9
-0+ *val2 =cmsr_get_time_unlocked (cm); + *val =1000000 ; +return IIO_VAL_FRACTIONAL ; + +default : +return -EINVAL ; + } +} +
Signature · 1 line
Jerome
David Lechner
reviewerRe: [PATCH 2/2] iio: frequency: add amlogic clock measure support
Quoted 24 lines · Jerome Brunet
Quoted 7 lines · David Lechner
Quoted 3 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
Quoted 14 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 642
Quoted 11 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +11
-0+static int cmsr_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct amlogic_cmsr *cm =iio_priv (indio_dev); + +guard (mutex)(&cm->lock); + +switch (mask) { +case IIO_CHAN_INFO_RAW : + *val =cmsr_measure_unlocked (cm, chan->channel);Is this actually returning an alternating voltage magnitutde? Most frequency drivers don't have a raw value, only frequency.
Quoted 3 lines
No it is not the magnitude, it is the clock rate (frequency) indeed. Maybe altvoltage was not the right pick for that but nothing obvious stands out for Hz measurements
I'm certainly not an expert on the subject, but looking at the other frequency drivers, using altvoltage looks correct.
But, we in those drivers, nearly all only have a "frequency" attribute but don't have a "raw" attribute. The ones that do have a "raw" attribute are frequency generators that use the raw attribute determine the output voltage.
Quoted 43 lines
Quoted 9 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 647
Quoted 7 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +5
-0+if (*val <0 ) +return *val; +return IIO_VAL_INT ; + +case IIO_CHAN_INFO_PROCESSED :/* Result in Hz */ Shouldn't this be
IIO_CHAN_INFO_FREQUENCY?How would I get raw / processed / scale with
IIO_CHAN_INFO_FREQUENCY?Quoted 3 lines
Processed is just (raw + offset) * scale which would be a voltage in this case since the channel type is
IIO_ALTVOLTAGE.This is was Processed does here, along with selecting the most appropriate scale to perform the measurement.
Quoted 9 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 653
Quoted 7 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +6
-0+ *val =cmsr_measure_processed_unlocked (cm, chan->channel, val2); +if (*val <0 ) +return *val; +return IIO_VAL_INT_64 ; + +case IIO_CHAN_INFO_SCALE :What is this attribute being used for?
Hz
Quoted 5 lines
(clearly not used to convert the raw value to millivolts :-) )
Maybe
IIO_CHAN_INFO_INT_TIMEis the right one for this? Although so far, that has only been used with light sensors.I think you are mixing up channel info and type here. I do want the info
*IIO_CHAN_INFO_RAW
*IIO_CHAN_INFO_PROCESSED
*IIO_CHAN_INFO_SCALE
Quoted 3 lines
I want those info to represent an alternate voltage frequency in Hz. I thought type '
IIO_ALTVOLTAGE' was the right pick for that. Apparently it is not. What is the appropriate type then ? Should I add a new one ?
The documentation at Documentation/ABI/testing/sysfs-bus-iio explains what the combination of a channel type and info means.
For example, out_altvoltageY_raw is defined as it used for the frequency generator case that I mentioned above. in_altvoltageY_raw is not defined which means probably no one has needed it yet. But it would still be the voltage value, not the frequency.
There also isn't a in_altvoltageY_input defined ("_input" is the sysfs name for IIO_CHAN_INFO_PROCESSED). But in general, "input" (processed) in IIO just means the value in standard units instead of a raw value. It doesn't mean that any extra signal processing was done. And "scale" is just a way to convert "raw" to "input" (processed). So channels will either have "raw" and "scale" or only have "input" (processed), but not both.
Could you describe at a higher level what the use case for the various values being exposed here are? I think that would be helpful in figuring out where they actually fit in to the standard IIO attributes.
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +9
-0+ *val2 =cmsr_get_time_unlocked (cm); + *val =1000000 ; +return IIO_VAL_FRACTIONAL ; + +default : +return -EINVAL ; + } +} +
Jerome Brunet
reviewerRe: [PATCH 2/2] iio: frequency: add amlogic clock measure support
Quoted 80 lines · David Lechner
Quoted 24 lines · Jerome Brunet
Quoted 7 lines · David Lechner
Quoted 3 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
Quoted 14 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 642
Quoted 11 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +11
-0+static int cmsr_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct amlogic_cmsr *cm =iio_priv (indio_dev); + +guard (mutex)(&cm->lock); + +switch (mask) { +case IIO_CHAN_INFO_RAW : + *val =cmsr_measure_unlocked (cm, chan->channel);Is this actually returning an alternating voltage magnitutde? Most frequency drivers don't have a raw value, only frequency.
Quoted 3 lines
No it is not the magnitude, it is the clock rate (frequency) indeed. Maybe altvoltage was not the right pick for that but nothing obvious stands out for Hz measurements
I'm certainly not an expert on the subject, but looking at the other frequency drivers, using altvoltage looks correct.
But, we in those drivers, nearly all only have a "frequency" attribute but don't have a "raw" attribute. The ones that do have a "raw" attribute are frequency generators that use the raw attribute determine the output voltage.
Quoted 43 lines
Quoted 9 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 647
Quoted 7 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +5
-0+if (*val <0 ) +return *val; +return IIO_VAL_INT ; + +case IIO_CHAN_INFO_PROCESSED :/* Result in Hz */ Shouldn't this be
IIO_CHAN_INFO_FREQUENCY?How would I get raw / processed / scale with
IIO_CHAN_INFO_FREQUENCY?Quoted 3 lines
Processed is just (raw + offset) * scale which would be a voltage in this case since the channel type is
IIO_ALTVOLTAGE.This is was Processed does here, along with selecting the most appropriate scale to perform the measurement.
Quoted 9 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 653
Quoted 7 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +6
-0+ *val =cmsr_measure_processed_unlocked (cm, chan->channel, val2); +if (*val <0 ) +return *val; +return IIO_VAL_INT_64 ; + +case IIO_CHAN_INFO_SCALE :What is this attribute being used for?
Hz
Quoted 5 lines
(clearly not used to convert the raw value to millivolts :-) )
Maybe
IIO_CHAN_INFO_INT_TIMEis the right one for this? Although so far, that has only been used with light sensors.I think you are mixing up channel info and type here. I do want the info
*IIO_CHAN_INFO_RAW
*IIO_CHAN_INFO_PROCESSED
*IIO_CHAN_INFO_SCALE
Quoted 7 lines
Quoted 3 lines
I want those info to represent an alternate voltage frequency in Hz. I thought type '
IIO_ALTVOLTAGE' was the right pick for that. Apparently it is not. What is the appropriate type then ? Should I add a new one ?The documentation at
Documentation/ABI/testing/sysfs-bus-iioexplains what the combination of a channel type and info means.
Oh missed that, Thx
Quoted 5 lines
For example,
out_altvoltageY_rawis defined as it used for the frequency generator case that I mentioned above.in_altvoltageY_rawis not defined which means probably no one has needed it yet. But it would still be the voltage value, not the frequency.
Got it. So the type I picked is wrong for sure. So, maybe I need something new to measure a frequency ?
Quoted 11 lines
There also isn't a
in_altvoltageY_inputdefined ("_input" is the sysfs name forIIO_CHAN_INFO_PROCESSED). But in general, "input" (processed) in IIO just means the value in standard units instead of a raw value. It doesn't mean that any extra signal processing was done. And "scale" is just a way to convert "raw" to "input" (processed). So channels will either have "raw" and "scale" or only have "input" (processed), but not both.Could you describe at a higher level what the use case for the various values being exposed here are? I think that would be helpful in figuring out where they actually fit in to the standard IIO attributes.
So as discussed in the cover letter, This HW used to be driven by a driver living in drivers/soc/amlogic/meson-clk-measure.c .
It provides debugfs entries to observe the rate of 128 system clocks. It was fine until now and mostly used for debug in userspace.
To solve a problem with implementing eARC support in ASoC, I need another driver to access the measurements, as simply as possible. IIO provides an interface like this and the HW actually does measurements so I seems like a good fit. I've got it to work and happy with the result, both on the IIO and ASoC side.
What is really important to me is the information provided with IIO_CHAN_INFO_PROCESSED, because the algorithm will adapt the scale (the duration the clock is observed for) to not overflow the output and get the best precision achievable. It is a compromise really. Consumer do not have to worry about it, they'll get Hz.
I'd prefer to avoid having that algorithm (duplicated) in the consumers, especially if it is a driver.
I've provided RAW and SCALE because it is cheap and easy to do TBH. I can live without it. It is meant for consumers (if any?) that would know better, like want to prioritize speed over precision.
Eventually that driver could evolve and also provide duty cycle measurements, which is another reason why I think IIO is a good fit for it.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +9
-0+ *val2 =cmsr_get_time_unlocked (cm); + *val =1000000 ; +return IIO_VAL_FRACTIONAL ; + +default : +return -EINVAL ; + } +} +
Signature · 1 line
Jerome
Jonathan Cameron
maintainerRe: [PATCH 2/2] iio: frequency: add amlogic clock measure support
Quoted 93 lines · On Tue, 25 Jun 2024 18:59:58 +0200 Jerome Brunet <[email protected]> wrote:
Quoted 80 lines · David Lechner
Quoted 24 lines · Jerome Brunet
Quoted 7 lines · David Lechner
Quoted 3 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
Quoted 14 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 642
Quoted 11 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +11
-0+static int cmsr_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct amlogic_cmsr *cm =iio_priv (indio_dev); + +guard (mutex)(&cm->lock); + +switch (mask) { +case IIO_CHAN_INFO_RAW : + *val =cmsr_measure_unlocked (cm, chan->channel);Is this actually returning an alternating voltage magnitutde? Most frequency drivers don't have a raw value, only frequency.
Quoted 3 lines
No it is not the magnitude, it is the clock rate (frequency) indeed. Maybe altvoltage was not the right pick for that but nothing obvious stands out for Hz measurements
I'm certainly not an expert on the subject, but looking at the other frequency drivers, using altvoltage looks correct.
But, we in those drivers, nearly all only have a "frequency" attribute but don't have a "raw" attribute. The ones that do have a "raw" attribute are frequency generators that use the raw attribute determine the output voltage.
Quoted 43 lines
Quoted 9 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 647
Quoted 7 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +5
-0+if (*val <0 ) +return *val; +return IIO_VAL_INT ; + +case IIO_CHAN_INFO_PROCESSED :/* Result in Hz */ Shouldn't this be
IIO_CHAN_INFO_FREQUENCY?How would I get raw / processed / scale with
IIO_CHAN_INFO_FREQUENCY?Quoted 3 lines
Processed is just (raw + offset) * scale which would be a voltage in this case since the channel type is
IIO_ALTVOLTAGE.This is was Processed does here, along with selecting the most appropriate scale to perform the measurement.
Quoted 9 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 653
Quoted 7 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +6
-0+ *val =cmsr_measure_processed_unlocked (cm, chan->channel, val2); +if (*val <0 ) +return *val; +return IIO_VAL_INT_64 ; + +case IIO_CHAN_INFO_SCALE :What is this attribute being used for?
Hz
Quoted 5 lines
(clearly not used to convert the raw value to millivolts :-) )
Maybe
IIO_CHAN_INFO_INT_TIMEis the right one for this? Although so far, that has only been used with light sensors.I think you are mixing up channel info and type here. I do want the info
*IIO_CHAN_INFO_RAW
*IIO_CHAN_INFO_PROCESSED
*IIO_CHAN_INFO_SCALEQuoted 7 lines
Quoted 3 lines
I want those info to represent an alternate voltage frequency in Hz. I thought type '
IIO_ALTVOLTAGE' was the right pick for that. Apparently it is not. What is the appropriate type then ? Should I add a new one ?The documentation at
Documentation/ABI/testing/sysfs-bus-iioexplains what the combination of a channel type and info means.Oh missed that, Thx
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
For example,
out_altvoltageY_rawis defined as it used for the frequency generator case that I mentioned above.in_altvoltageY_rawis not defined which means probably no one has needed it yet. But it would still be the voltage value, not the frequency.Got it. So the type I picked is wrong for sure. So, maybe I need something new to measure a frequency ?
Yes. Seems likely we need a new channel type to me.
In theory we could abuse an angular rate channel but that's nasty so lets not do that. :)
Jonathan
Jonathan Cameron
maintainerRe: [PATCH 2/2] iio: frequency: add amlogic clock measure support
In reply to Jerome BrunetQuoted 6 lines · On Mon, 24 Jun 2024 19:31:03 +0200 Jerome Brunet <[email protected]> wrote:
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found in
drivers/soc/amlogic/meson-clk-measure.cwith following improvements:
Quoted 6 lines
* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurementsSigned-off-by Jerome Brunet <[email protected]>
Interesting device and the driver is pretty clean.
Needs a new channel type though as altvoltage is in volts not hz.
Various minor comments inline.
Thanks,
Jonathan
drivers/iio/frequency/amlogic-clk-msr-io.c line 46
Quoted 5 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +5
-0+ +struct amlogic_cmsr { +struct regmap *reg; +struct regmap *duty; +struct mutex lock;
Add a comment on the data protected by this lock. Scope isn't always obvious.
Quoted 4 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +3
-0+}; +static struct iio_chan_spec *cmsr_populate_channels (struct device *dev, +const char *const *conf)
drivers/iio/frequency/amlogic-clk-msr-io.c line 499
Quoted 10 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +10
-0+{ +struct iio_chan_spec *chan; +int i; + + chan =devm_kzalloc (dev,sizeof (*chan) *CLK_MSR_MAX ,GFP_KERNEL ); +if (!chan) +return ERR_PTR (-ENOMEM ); + +for (i =0 ; i <CLK_MSR_MAX ; i++) { + chan[i].type =IIO_ALTVOLTAGE ;
As per other branch of the thread. I think this needs to be a new IIO_FREQUENCY channel as the input we care about here is simply frequency, not the voltage.
drivers/iio/frequency/amlogic-clk-msr-io.c line 503
Quoted 4 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +4
-0+ chan[i].indexed =1 ; + chan[i].channel = i; + chan[i].info_mask_separate = (BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_PROCESSED ));
Drop outer ()
Quoted 37 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +35
-0+ chan[i].info_mask_shared_by_type =BIT (IIO_CHAN_INFO_SCALE ); + chan[i].datasheet_name = conf[i]; + } + +return chan; +} +static int cmsr_measure_processed_unlocked (struct amlogic_cmsr *cm, +unsigned int idx, +int *val2) +{ +unsigned int time =CLK_MIN_TIME ; +u64 rate; +int ret; + +/* +* The challenge here is to provide the best accuracy +* while not spending to much time doing it. +* - Starting with a short duration risk not detecting +* slow clocks, but it is fast. All 128 can be done in ~8ms +* - Starting with a long duration risk overflowing the +* measurement counter and would be way to long, especially +* considering the number of disabled clocks. ~4s for all +* 128 worst case. +* +* This IP measures system clocks so all clock are expected +* to be 1kHz < f < 8GHz. We can compromise based on this, +* doing it in 3 pass: +* #1 Starting if 64us window: detects 30kHz < f < 8GHz +* - Go to #2 if no detection, Go to #3 otherwise +* #2 Extend duration to 1024us (f > 1kHz) +- Assume f = 0Hz if no detection, Go to #3 otherwise +* #3 Clock has been detected, adjust window for best accuracy +* +* Doing the range detection takes ~1ms per clock, including disabled +clocks.
drivers/iio/frequency/amlogic-clk-msr-io.c line 601
Quoted 10 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +10
-0+* Actual measurement takes at most ~65ms in step #3 for slow clocks, +* when the full range the HW is used. +*/ + +/* Step #1 - quick measurement */ +cmsr_set_time_unlocked (cm, time); + ret =cmsr_measure_unlocked (cm, idx); +if (ret <0 ) +return ret; +
if (ret == 0)
drivers/iio/frequency/amlogic-clk-msr-io.c line 609
Quoted 8 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +8
-0+else if (ret ==0 ) { +/* Step #2 - extend the window if necessary */ + time *=16 ; +cmsr_set_time_unlocked (cm, time); + ret =cmsr_measure_unlocked (cm, idx); +if (ret <0 ) +return ret; +
if (ret == 0)
Quoted 29 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +26
-0+else if (ret ==0 ) { +/* Still nothing - assume no clock */ + *val2 =0 ; +return 0 ; + } + } + +/* Step #3: Adapt scale for better precision */ + time = time *MSR_MEASURED *3 / (ret *4 );/* 25% margin */ + time = min_t(unsigned int, MSR_TIME_MAX, time); + +/* Actually measure rate with an optimized scale */ +cmsr_set_time_unlocked (cm, time); + ret =cmsr_measure_unlocked (cm, idx); +if (ret <0 ) +return ret; + + rate =DIV_ROUND_CLOSEST_ULL (ret *1000000ULL , time); + *val2 = rate >>32ULL ; +return (int )rate; +} +static int cmsr_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct iio_dev *indio_dev; +struct amlogic_cmsr *cm;
drivers/iio/frequency/amlogic-clk-msr-io.c
Quoted 10 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +10
-0+const char *const *conf; +void __iomem *regs; + + indio_dev =devm_iio_device_alloc (dev,sizeof (*cm)); +if (!indio_dev) +return -ENOMEM ; +platform_set_drvdata (pdev, indio_dev); + cm =iio_priv (indio_dev); + + conf =of_device_get_match_data (dev);
We try to avoid of specific calls in IIO drivers.device_get_match_data() should work here.
Reason for this is not that it matters in one driver, but that people tend to cut and paste device tree stuff and it ends up in drivers where ACPI and other firmware types are relevant.
Also I only have remember how one type of firmware property read call works ;)
Quoted 15 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +15
-0+if (!conf) { +dev_err (dev,"failed to match device\n" ); +return -ENODEV ; + } + + regs =devm_platform_ioremap_resource_byname (pdev,"reg" ); +if (IS_ERR (regs)) +return PTR_ERR (regs); + + cm->reg =devm_regmap_init_mmio (dev, regs, &cmsr_regmap_cfg); +if (IS_ERR (cm->reg)) { +dev_err (dev,"failed to init main regmap: %ld\n" , +PTR_ERR (cm->reg)); +return PTR_ERR (cm->reg); + }
drivers/iio/frequency/amlogic-clk-msr-io.c line 772
Quoted 10 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +10
-0+ + regs =devm_platform_ioremap_resource_byname (pdev,"duty" ); +if (IS_ERR (regs)) +return PTR_ERR (regs); + + cm->duty =devm_regmap_init_mmio (dev, regs, &cmsr_regmap_cfg); +if (IS_ERR (cm->duty)) { +dev_err (dev,"failed to init duty regmap: %ld\n" , +PTR_ERR (cm->duty)); +return PTR_ERR (cm->duty);
Preference for dev_err_probe() for all errors in probe() and functions that will only be called form probe. There is a nice version that handled PTR_ERR under review though so maybe we can come around later and use that once it's available
drivers/iio/frequency/amlogic-clk-msr-io.c line 783
Quoted 11 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +11
-0+ } + +mutex_init (&cm->lock); + +/* Init scale with a sane default */ +cmsr_set_time_unlocked (cm,CLK_MIN_TIME ); + + indio_dev->name ="amlogic-clk-msr" ; + indio_dev->info = &cmsr_info; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->num_channels =CLK_MSR_MAX ;
Superficially looks like the number of channels depends on the compatible. Ideally we shouldn't provide channels to userspace that aren't useful.
You could search the name arrays to see how far they go, but that is bit ugly. Probably wrap those in a structure with a num_channels parameter as well.
Quoted 6 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +6
-0+ indio_dev->channels =cmsr_populate_channels (dev, conf); +if (IS_ERR (indio_dev->channels)) +return PTR_ERR (indio_dev->channels); + +return devm_iio_device_register (dev, indio_dev); +}
Jerome Brunet
reviewerRe: [PATCH 2/2] iio: frequency: add amlogic clock measure support
Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Mon, 24 Jun 2024 19:31:03 +0200 Jerome Brunet <[email protected]> wrote:
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found in
drivers/soc/amlogic/meson-clk-measure.cwith following improvements:* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurements
Quoted 8 lines
Quoted 1 line
Signed-off-by Jerome Brunet <[email protected]>Interesting device and the driver is pretty clean.
Needs a new channel type though as altvoltage is in volts not hz.
Various minor comments inline.
Thanks,
Thanks for the feedback Jonathan.
Just a couple of things,
David expressed concerns with having both IIO_CHAN_INFO_RAW and IIO_CHAN_INFO_PROCESSED for a channel and we did not reach a conclusion on this.
My idea here is to:
* Give full control over the scale to the consumer with IIO_CHAN_INFO_RAW
* Give an easy/convenient way to get an Hz result with IIO_CHAN_INFO_PROCESSED. There is a bit more than just 'raw * scale' in the implementation of this info to figure out the most appropriate scale for the measurement. They idea is also to avoid code duplication in consumers.
David is definitely more familiar than me with IIO but we did not really know how to move forward on this.
Is it OK to have both IIO_CHAN_INFO_RAW and IIO_CHAN_INFO_PROCESSED, or should I ditch IIO_CHAN_INFO_RAW ?
Quoted 2 lines
Jonathan
[...]
Quoted 7 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 783
Quoted 4 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +4
-0+ indio_dev->name ="amlogic-clk-msr" ; + indio_dev->info = &cmsr_info; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->num_channels =CLK_MSR_MAX ;Superficially looks like the number of channels depends on the compatible. Ideally we shouldn't provide channels to userspace that aren't useful.
Not exactly. All SoCs have 128 inputs, Some may not be connected indeed but some are, and the name is just not documented (yet).
Quoted 4 lines
You could search the name arrays to see how far they go, but that is bit ugly. Probably wrap those in a structure with a
num_channelsparameter as well.
I've been doodling with this idea while writing this driver. Technically, there is no problem.
The legacy driver this one will be replacing used to expose all 128 inputs. I thought it was more important to have continuity with the legacy driver than filtering out possibly useless channels.
Another benefit of keeping all 128 is that the channel index (both in sysfs and more crucially in DT) matches the one in the SoC documentation. That makes things easier.
Would it be acceptable to keep all 128 channels then or do you still prefer that I filter out the undocumented ones ?
Quoted 6 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 789
Quoted 6 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +6
-0+ indio_dev->channels =cmsr_populate_channels (dev, conf); +if (IS_ERR (indio_dev->channels)) +return PTR_ERR (indio_dev->channels); + +return devm_iio_device_register (dev, indio_dev); +}
Thanks for you help.
Signature · 1 line
Jerome
Jonathan Cameron
maintainerRe: [PATCH 2/2] iio: frequency: add amlogic clock measure support
Quoted 33 lines · On Sun, 30 Jun 2024 09:21:03 +0200 Jerome Brunet <[email protected]> wrote:
Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Mon, 24 Jun 2024 19:31:03 +0200 Jerome Brunet <[email protected]> wrote:
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found in
drivers/soc/amlogic/meson-clk-measure.cwith following improvements:* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurementsQuoted 8 lines
Quoted 1 line
Signed-off-by Jerome Brunet <[email protected]>Interesting device and the driver is pretty clean.
Needs a new channel type though as altvoltage is in volts not hz.
Various minor comments inline.
Thanks,
Thanks for the feedback Jonathan.
Just a couple of things,
David expressed concerns with having both
IIO_CHAN_INFO_RAWandIIO_CHAN_INFO_PROCESSEDfor a channel and we did not reach a conclusion on this.
Quoted 8 lines
My idea here is to:
* Give full control over the scale to the consumer withIIO_CHAN_INFO_RAW
* Give an easy/convenient way to get an Hz result withIIO_CHAN_INFO_PROCESSED. There is a bit more than just 'raw * scale' in the implementation of this info to figure out the most appropriate scale for the measurement. They idea is also to avoid code duplication in consumers.
So we have had a few cases of software driving autorange finding for sensors in the past (typically light sensors). An example is the gp2ap020a00f driver but those have been been driven by interrupts to detect range issue and are much more complex than what you have here. Note that driver only provides _RAW, I think because we have no documentation of how to convert to an illuminance reading. It's old though and probably not a good example to follow.
Quoted 6 lines
David is definitely more familiar than me with IIO but we did not really know how to move forward on this.
Is it OK to have both
IIO_CHAN_INFO_RAWandIIO_CHAN_INFO_PROCESSED, or should I ditchIIO_CHAN_INFO_RAW?
I'll ask the obvious question - do you have a usecase for _RAW + _SCALE if not we can take the conservative approach of not providing it 'yet' and revisit once that use case surfaces.
Otherwise, I tend to resist mixing processed and raw + scale just because it makes it hard for userspace to understand the difference. This combination has only happened in the past due to driver evolution (we got it wrong initially for a given driver).
So I'm not strongly against providing both (and amending my standard 'don't do this reply' to include this as a special case) but I want to know someone actually cares.
Quoted 22 lines
Quoted 3 lines
Jonathan
[...]
Quoted 7 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 783
Quoted 4 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +4
-0+ indio_dev->name ="amlogic-clk-msr" ; + indio_dev->info = &cmsr_info; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->num_channels =CLK_MSR_MAX ;Superficially looks like the number of channels depends on the compatible. Ideally we shouldn't provide channels to userspace that aren't useful.
Not exactly. All SoCs have 128 inputs, Some may not be connected indeed but some are, and the name is just not documented (yet).
Quoted 4 lines
You could search the name arrays to see how far they go, but that is bit ugly. Probably wrap those in a structure with a
num_channelsparameter as well.
Quoted 6 lines
I've been doodling with this idea while writing this driver. Technically, there is no problem.
The legacy driver this one will be replacing used to expose all 128 inputs. I thought it was more important to have continuity with the legacy driver than filtering out possibly useless channels.
ok.
Quoted 7 lines
Another benefit of keeping all 128 is that the channel index (both in sysfs and more crucially in DT) matches the one in the SoC documentation. That makes things easier.
Would it be acceptable to keep all 128 channels then or do you still prefer that I filter out the undocumented ones ?
Your explanation for why we should keep them is fine. Add some suitable comments so we don't forget it.
Quoted 10 lines
Quoted 7 lines
drivers/iio/frequency/amlogic-clk-msr-io.c line 789
Quoted 7 lines
drivers/iio/frequency/amlogic-clk-msr-io.c new file +6
-0+ indio_dev->channels =cmsr_populate_channels (dev, conf); +if (IS_ERR (indio_dev->channels)) +return PTR_ERR (indio_dev->channels); + +return devm_iio_device_register (dev, indio_dev); +}Thanks for you help.
You are welcome
J
Neil Armstrong
maintainerHi,
[+cc people from linux-msm]
Quoted 15 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found in
drivers/soc/amlogic/meson-clk-measure.cwith following improvements:* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurementsJerome Brunet (2):
dt-bindings: iio: frequency: add clock measure support
iio: frequency: add amlogic clock measure support
Quoted 8 lines
.../iio/frequency/amlogic,clk-msr-io.yaml | 50 ++ drivers/iio/frequency/Kconfig | 15 + drivers/iio/frequency/Makefile | 1 + drivers/iio/frequency/amlogic-clk-msr-io.c | 802 ++++++++++++++++++ 4 files changed, 868 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/frequency/amlogic,clk-msr-io.yamlcreate mode 100644drivers/iio/frequency/amlogic-clk-msr-io.c
While I really appreciate the effort, and the code looks cool, the clkmsr is really a debug tool, and I'm not sure IIO is the right place for such debug tool ?
There's almost the same interface on qcom SoCs (https://github.com/linux-msm/debugcc) but they chose to keep it in userspace until we find an appropriate way to expose this from the kernel the right way.
If it enabled us to monitor a frequency input for a product use-case, IIO would be the appropriate interface, but AFAIK it's only internal clocks and thus I'm worried it's not the best way to expose those clocks.
Neil
Jerome Brunet
reviewerQuoted 25 lines · Neil Armstrong
Hi,
[+cc people from linux-msm]
Quoted 11 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found indrivers/soc/amlogic/meson-clk-measure.cwith following improvements:
* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurements
Jerome Brunet (2):
dt-bindings: iio: frequency: add clock measure support
iio: frequency: add amlogic clock measure supportQuoted 8 lines
.../iio/frequency/amlogic,clk-msr-io.yaml | 50 ++ drivers/iio/frequency/Kconfig | 15 + drivers/iio/frequency/Makefile | 1 + drivers/iio/frequency/amlogic-clk-msr-io.c | 802 ++++++++++++++++++ 4 files changed, 868 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/frequency/amlogic,clk-msr-io.yamlcreate mode 100644drivers/iio/frequency/amlogic-clk-msr-io.c
Quoted 2 lines
While I really appreciate the effort, and the code looks cool, the clkmsr is really a debug tool, and I'm not sure IIO is the right place for such debug tool ?
The reason why I went through the trouble of doing an IIO port is because I need that for other purposes than debug. I need to to be able to check a frequency from another driver. I don't see a reason to invent another API when IIO provide a perfectly good one.
The HW does measurements. IIO seems like the best place for it.
For the record, I need this for a eARC support.
eARC has a PLL that locks on incoming stream. eARC registers show wether the PLL is locked or not, but not at which rate. That information is needed in ASoC. Fortunately the eARC PLL is one of measured clock, which is a life saver in that case.
Everything that was available through the old driver still is, with more precision and more control.
Quoted 10 lines
There's almost the same interface on qcom SoCs (https://github.com/linux-msm/debugcc) but they chose to keep it in userspace until we find an appropriate way to expose this from the kernel the right way.
If it enabled us to monitor a frequency input for a product use-case, IIO would be the appropriate interface, but AFAIK it's only internal clocks and thus I'm worried it's not the best way to expose those clocks.
Neil
Signature · 1 line
Jerome
Neil Armstrong
maintainerQuoted 35 lines · Jerome Brunet
Quoted 25 lines · Neil Armstrong
Hi,
[+cc people from linux-msm]
Quoted 11 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found indrivers/soc/amlogic/meson-clk-measure.cwith following improvements:
* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurements
Jerome Brunet (2):
dt-bindings: iio: frequency: add clock measure support
iio: frequency: add amlogic clock measure supportQuoted 8 lines
.../iio/frequency/amlogic,clk-msr-io.yaml | 50 ++ drivers/iio/frequency/Kconfig | 15 + drivers/iio/frequency/Makefile | 1 + drivers/iio/frequency/amlogic-clk-msr-io.c | 802 ++++++++++++++++++ 4 files changed, 868 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/frequency/amlogic,clk-msr-io.yamlcreate mode 100644drivers/iio/frequency/amlogic-clk-msr-io.cQuoted 2 lines
While I really appreciate the effort, and the code looks cool, the clkmsr is really a debug tool, and I'm not sure IIO is the right place for such debug tool ?
The reason why I went through the trouble of doing an IIO port is because I need that for other purposes than debug. I need to to be able to check a frequency from another driver. I don't see a reason to invent another API when IIO provide a perfectly good one.
Quoted 7 lines
The HW does measurements. IIO seems like the best place for it.
For the record, I need this for a eARC support.
eARC has a PLL that locks on incoming stream. eARC registers show wether the PLL is locked or not, but not at which rate. That information is needed in ASoC. Fortunately the eARC PLL is one of measured clock, which is a life saver in that case.
This is a very interesting use-case, and quite weird nothing is provided on the eARC side.
So yes it's definitely a valid use-case, but:
- we should keep the debugfs interface, perhaps move it in the iio driver ?
- we should keep a single compatible, so simply update the current bindings with iio cells
- for s4 & c3, it's ok to either add a second reg entry in the bindings
Neil
Quoted 15 lines
Everything that was available through the old driver still is, with more precision and more control.
Quoted 10 lines
There's almost the same interface on qcom SoCs (https://github.com/linux-msm/debugcc) but they chose to keep it in userspace until we find an appropriate way to expose this from the kernel the right way.
If it enabled us to monitor a frequency input for a product use-case, IIO would be the appropriate interface, but AFAIK it's only internal clocks and thus I'm worried it's not the best way to expose those clocks.
Neil
Jerome Brunet
reviewerQuoted 41 lines · Neil Armstrong
Quoted 29 lines · Jerome Brunet
Quoted 25 lines · Neil Armstrong
Hi,
[+cc people from linux-msm]
Quoted 11 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found indrivers/soc/amlogic/meson-clk-measure.cwith following improvements:
* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurements
Jerome Brunet (2):
dt-bindings: iio: frequency: add clock measure support
iio: frequency: add amlogic clock measure supportQuoted 8 lines
.../iio/frequency/amlogic,clk-msr-io.yaml | 50 ++ drivers/iio/frequency/Kconfig | 15 + drivers/iio/frequency/Makefile | 1 + drivers/iio/frequency/amlogic-clk-msr-io.c | 802 ++++++++++++++++++ 4 files changed, 868 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/frequency/amlogic,clk-msr-io.yamlcreate mode 100644drivers/iio/frequency/amlogic-clk-msr-io.cQuoted 2 lines
While I really appreciate the effort, and the code looks cool, the clkmsr is really a debug tool, and I'm not sure IIO is the right place for such debug tool ?
Quoted 10 lines
The reason why I went through the trouble of doing an IIO port is because I need that for other purposes than debug. I need to to be able to check a frequency from another driver. I don't see a reason to invent another API when IIO provide a perfectly good one.
The HW does measurements. IIO seems like the best place for it. For the record, I need this for a eARC support.
eARC has a PLL that locks on incoming stream. eARC registers show wether the PLL is locked or not, but not at which rate. That information is needed in ASoC. Fortunately the eARC PLL is one of measured clock, which is a life saver in that case.
Quoted 2 lines
This is a very interesting use-case, and quite weird nothing is provided on the eARC side.
Indeed.
Quoted 3 lines
So yes it's definitely a valid use-case, but:
- we should keep the debugfs interface, perhaps move it in the iio driver ?
I considered this initially but it would add a lot of boiler plate code to provide over debugfs exactly what iio already provides over sysfs. As you pointed out, the previous driver only provided debug information, the debugfs interface it provided is hardly a critical/stable one.
Quoted 1 line
- we should keep a single compatible, so simply update the current bindings with iio cells
Using a new compatible allows to split the memory region, making the interface between DT and driver a lot easier to implement seemlessly between old and new SoCs. Eventually it may allow to implement the duty part too.
Quoted 1 line
- for s4 & c3, it's ok to either add a second reg entry in the bindings
Doing that for s4 and c3 only would still make a mess of offset handling the region because duty prepend the region on old SoC. The goal is to have an interface that seemlessly support both old and new SoCs.
Quoted 17 lines
Neil
Quoted 14 lines
Everything that was available through the old driver still is, with more precision and more control.
Quoted 10 lines
There's almost the same interface on qcom SoCs (https://github.com/linux-msm/debugcc) but they chose to keep it in userspace until we find an appropriate way to expose this from the kernel the right way.
If it enabled us to monitor a frequency input for a product use-case, IIO would be the appropriate interface, but AFAIK it's only internal clocks and thus I'm worried it's not the best way to expose those clocks.
Neil
Signature · 1 line
Jerome
Neil Armstrong
maintainerQuoted 49 lines · Jerome Brunet
Quoted 41 lines · Neil Armstrong
Quoted 29 lines · Jerome Brunet
Quoted 25 lines · Neil Armstrong
Hi,
[+cc people from linux-msm]
Quoted 10 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found indrivers/soc/amlogic/meson-clk-measure.cwith following improvements:
* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurements
Jerome Brunet (2):
dt-bindings: iio: frequency: add clock measure supportQuoted 9 lines
iio: frequency: add amlogic clock measure support
.../iio/frequency/amlogic,clk-msr-io.yaml| 50 ++
drivers/iio/frequency/Kconfig| 15 +
drivers/iio/frequency/Makefile| 1 +
drivers/iio/frequency/amlogic-clk-msr-io.c| 802 ++++++++++++++++++
4 files changed, 868 insertions(+)
create mode 100644Documentation/devicetree/bindings/iio/frequency/amlogic,clk-msr-io.yamlcreate mode 100644drivers/iio/frequency/amlogic-clk-msr-io.cQuoted 2 lines
While I really appreciate the effort, and the code looks cool, the clkmsr is really a debug tool, and I'm not sure IIO is the right place for such debug tool ?
Quoted 10 lines
The reason why I went through the trouble of doing an IIO port is because I need that for other purposes than debug. I need to to be able to check a frequency from another driver. I don't see a reason to invent another API when IIO provide a perfectly good one.
The HW does measurements. IIO seems like the best place for it. For the record, I need this for a eARC support.
eARC has a PLL that locks on incoming stream. eARC registers show wether the PLL is locked or not, but not at which rate. That information is needed in ASoC. Fortunately the eARC PLL is one of measured clock, which is a life saver in that case.Quoted 2 lines
This is a very interesting use-case, and quite weird nothing is provided on the eARC side.
Indeed.
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
So yes it's definitely a valid use-case, but:
- we should keep the debugfs interface, perhaps move it in the iio driver ?I considered this initially but it would add a lot of boiler plate code to provide over debugfs exactly what iio already provides over sysfs. As you pointed out, the previous driver only provided debug information, the debugfs interface it provided is hardly a critical/stable one.
I still don't see why it could add so much boilerplate, all the tables and calculation fonction would be shared, only the debugfs clk_msr_show() and clk_msr_summary_show() would be kept, all the rest would be common.
I insist, please keep the debugfs interface for debug purposes. You don't want to mess with IIO when you bring up new platforms with bare minimum kernels.
Quoted 7 lines
Quoted 2 lines
- we should keep a single compatible, so simply update the current bindings with iio cells
Using a new compatible allows to split the memory region, making the interface between DT and driver a lot easier to implement seemlessly between old and new SoCs. Eventually it may allow to implement the duty part too.
It's a problem for new platforms, you can introduce the split only for the new ones, the impact on code won't high enough to justify new bindings.
Neil
Quoted 25 lines
Quoted 2 lines
- for s4 & c3, it's ok to either add a second reg entry in the bindings
Doing that for s4 and c3 only would still make a mess of offset handling the region because duty prepend the region on old SoC. The goal is to have an interface that seemlessly support both old and new SoCs.
Quoted 17 lines
Neil
Quoted 14 lines
Everything that was available through the old driver still is, with more precision and more control.
Quoted 10 lines
There's almost the same interface on qcom SoCs (https://github.com/linux-msm/debugcc) but they chose to keep it in userspace until we find an appropriate way to expose this from the kernel the right way.
If it enabled us to monitor a frequency input for a product use-case, IIO would be the appropriate interface, but AFAIK it's only internal clocks and thus I'm worried it's not the best way to expose those clocks.
Neil
Jerome Brunet
reviewerQuoted 57 lines · Neil Armstrong
Quoted 48 lines · Jerome Brunet
Quoted 41 lines · Neil Armstrong
Quoted 29 lines · Jerome Brunet
Quoted 25 lines · Neil Armstrong
Hi,
[+cc people from linux-msm]
Quoted 10 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found indrivers/soc/amlogic/meson-clk-measure.cwith following improvements:
* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurements
Jerome Brunet (2):
dt-bindings: iio: frequency: add clock measure supportQuoted 9 lines
iio: frequency: add amlogic clock measure support
.../iio/frequency/amlogic,clk-msr-io.yaml| 50 ++
drivers/iio/frequency/Kconfig| 15 +
drivers/iio/frequency/Makefile| 1 +
drivers/iio/frequency/amlogic-clk-msr-io.c| 802 ++++++++++++++++++
4 files changed, 868 insertions(+)
create mode 100644Documentation/devicetree/bindings/iio/frequency/amlogic,clk-msr-io.yamlcreate mode 100644drivers/iio/frequency/amlogic-clk-msr-io.cQuoted 2 lines
While I really appreciate the effort, and the code looks cool, the clkmsr is really a debug tool, and I'm not sure IIO is the right place for such debug tool ?
Quoted 10 lines
The reason why I went through the trouble of doing an IIO port is because I need that for other purposes than debug. I need to to be able to check a frequency from another driver. I don't see a reason to invent another API when IIO provide a perfectly good one.
The HW does measurements. IIO seems like the best place for it. For the record, I need this for a eARC support.
eARC has a PLL that locks on incoming stream. eARC registers show wether the PLL is locked or not, but not at which rate. That information is needed in ASoC. Fortunately the eARC PLL is one of measured clock, which is a life saver in that case.Quoted 2 lines
This is a very interesting use-case, and quite weird nothing is provided on the eARC side.
Indeed.
Quoted 1 line
Quoted 7 lines
Quoted 2 lines
So yes it's definitely a valid use-case, but:
- we should keep the debugfs interface, perhaps move it in the iio driver ?I considered this initially but it would add a lot of boiler plate code to provide over debugfs exactly what iio already provides over sysfs. As you pointed out, the previous driver only provided debug information, the debugfs interface it provided is hardly a critical/stable one.
Quoted 7 lines
I still don't see why it could add so much boilerplate, all the tables and calculation fonction would be shared, only the debugfs
clk_msr_show()andclk_msr_summary_show()would be kept, all the rest would be common.I insist, please keep the debugfs interface for debug purposes. You don't want to mess with IIO when you bring up new platforms with bare minimum kernels.
I don't think that is going to change anything. It's not like IIO brings any complexity or will be compiled out.
But since you insist, I'll add it in the next version as a separate patch.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
- we should keep a single compatible, so simply update the current bindings with iio cells
Using a new compatible allows to split the memory region, making the interface between DT and driver a lot easier to implement seemlessly between old and new SoCs. Eventually it may allow to implement the duty part too.
It's a problem for new platforms, you can introduce the split only for the new ones, the impact on code won't high enough to justify new bindings.
What you are requesting will introduce two drivers providing the same compatible, unless you plan on removing the old one in a coordinated way.
That's an unncessary churn. The old driver could stay there for a while and platform slowly migrate. What you are requesting forcefully migrates every consumer, assuming the old driver is compiled out.
This is an opportunity to more correctly describe the interface. It does not break any DT rules, that is enough of a justification IMO.
Quoted 26 lines
Neil
Quoted 24 lines
Quoted 2 lines
- for s4 & c3, it's ok to either add a second reg entry in the bindings
Doing that for s4 and c3 only would still make a mess of offset handling the region because duty prepend the region on old SoC. The goal is to have an interface that seemlessly support both old and new SoCs.
Quoted 17 lines
Neil
Quoted 14 lines
Everything that was available through the old driver still is, with more precision and more control.
Quoted 10 lines
There's almost the same interface on qcom SoCs (https://github.com/linux-msm/debugcc) but they chose to keep it in userspace until we find an appropriate way to expose this from the kernel the right way.
If it enabled us to monitor a frequency input for a product use-case, IIO would be the appropriate interface, but AFAIK it's only internal clocks and thus I'm worried it's not the best way to expose those clocks.
Neil
Signature · 1 line
Jerome
Neil Armstrong
maintainerQuoted 88 lines · Jerome Brunet
Quoted 57 lines · Neil Armstrong
Quoted 48 lines · Jerome Brunet
Quoted 41 lines · Neil Armstrong
Quoted 29 lines · Jerome Brunet
Quoted 25 lines · Neil Armstrong
Hi,
[+cc people from linux-msm]
Quoted 10 lines · Jerome Brunet
Add support for the HW found in most Amlogic SoC dedicated to measure system clocks.
This drivers aims to replace the one found indrivers/soc/amlogic/meson-clk-measure.cwith following improvements:
* Access to the measurements through the IIO API:
Easier re-use of the results in userspace and other drivers
* Controllable scale with raw measurements
* Higher precision with processed measurements
Jerome Brunet (2):
dt-bindings: iio: frequency: add clock measure supportQuoted 9 lines
iio: frequency: add amlogic clock measure support
.../iio/frequency/amlogic,clk-msr-io.yaml| 50 ++
drivers/iio/frequency/Kconfig| 15 +
drivers/iio/frequency/Makefile| 1 +
drivers/iio/frequency/amlogic-clk-msr-io.c| 802 ++++++++++++++++++
4 files changed, 868 insertions(+)
create mode 100644Documentation/devicetree/bindings/iio/frequency/amlogic,clk-msr-io.yamlcreate mode 100644drivers/iio/frequency/amlogic-clk-msr-io.cQuoted 2 lines
While I really appreciate the effort, and the code looks cool, the clkmsr is really a debug tool, and I'm not sure IIO is the right place for such debug tool ?
Quoted 10 lines
The reason why I went through the trouble of doing an IIO port is because I need that for other purposes than debug. I need to to be able to check a frequency from another driver. I don't see a reason to invent another API when IIO provide a perfectly good one.
The HW does measurements. IIO seems like the best place for it. For the record, I need this for a eARC support.
eARC has a PLL that locks on incoming stream. eARC registers show wether the PLL is locked or not, but not at which rate. That information is needed in ASoC. Fortunately the eARC PLL is one of measured clock, which is a life saver in that case.Quoted 2 lines
This is a very interesting use-case, and quite weird nothing is provided on the eARC side.
Indeed.
Quoted 1 line
Quoted 7 lines
Quoted 2 lines
So yes it's definitely a valid use-case, but:
- we should keep the debugfs interface, perhaps move it in the iio driver ?I considered this initially but it would add a lot of boiler plate code to provide over debugfs exactly what iio already provides over sysfs. As you pointed out, the previous driver only provided debug information, the debugfs interface it provided is hardly a critical/stable one.
Quoted 7 lines
I still don't see why it could add so much boilerplate, all the tables and calculation fonction would be shared, only the debugfs
clk_msr_show()andclk_msr_summary_show()would be kept, all the rest would be common.I insist, please keep the debugfs interface for debug purposes. You don't want to mess with IIO when you bring up new platforms with bare minimum kernels.
I don't think that is going to change anything. It's not like IIO brings any complexity or will be compiled out.
But since you insist, I'll add it in the next version as a separate patch.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
- we should keep a single compatible, so simply update the current bindings with iio cells
Using a new compatible allows to split the memory region, making the interface between DT and driver a lot easier to implement seemlessly between old and new SoCs. Eventually it may allow to implement the duty part too.
It's a problem for new platforms, you can introduce the split only for the new ones, the impact on code won't high enough to justify new bindings.
What you are requesting will introduce two drivers providing the same compatible, unless you plan on removing the old one in a coordinated way.
Quoted 6 lines
That's an unncessary churn. The old driver could stay there for a while and platform slowly migrate. What you are requesting forcefully migrates every consumer, assuming the old driver is compiled out.
This is an opportunity to more correctly describe the interface. It does not break any DT rules, that is enough of a justification IMO.
DT describes the Hardware, I don't see how the new bindings describes better the current hardware... tying the new bindings to a new driver is actually against the DT rules, the bindings thing is actually to avoid that. For PWM, bindings architecture was clearly wrong, but here, not really.
I still don't see the problem of migrating current users to the new driver using the current compatible, really, please explain what would be the problem ?
In any case you'll only need to add the #io-channel-cells to boards that would require frequency monitoring for eARC, for all the other boards you'll won't need it. So this property can safely be added as optional to the current bindings.
Neil
Quoted 28 lines
Quoted 27 lines
Neil
Quoted 24 lines
Quoted 2 lines
- for s4 & c3, it's ok to either add a second reg entry in the bindings
Doing that for s4 and c3 only would still make a mess of offset handling the region because duty prepend the region on old SoC. The goal is to have an interface that seemlessly support both old and new SoCs.
Quoted 17 lines
Neil
Quoted 14 lines
Everything that was available through the old driver still is, with more precision and more control.
Quoted 10 lines
There's almost the same interface on qcom SoCs (https://github.com/linux-msm/debugcc) but they chose to keep it in userspace until we find an appropriate way to expose this from the kernel the right way.
If it enabled us to monitor a frequency input for a product use-case, IIO would be the appropriate interface, but AFAIK it's only internal clocks and thus I'm worried it's not the best way to expose those clocks.
Neil