* [PATCH 0/2] counter: Introduce the compare component
@ 2025-03-06 7:05 William Breathitt Gray
2025-03-06 7:05 ` [PATCH 1/2] " William Breathitt Gray
2025-03-06 7:05 ` [PATCH 2/2] counter: microchip-tcb-capture: Add support for RC Compare William Breathitt Gray
0 siblings, 2 replies; 6+ messages in thread
From: William Breathitt Gray @ 2025-03-06 7:05 UTC (permalink / raw)
To: csokas.bence, Kamel Bouhara
Cc: linux-iio, linux-kernel, linux-arm-kernel, William Breathitt Gray
In previous drivers, we have exposed compare operations as part of a
larger set of functionalities; such as preseting a Count channel,
defining ceiling and floor boundaries, etc. However, we've lacked a
standard way to expose the compare operation in its strict sense as a
threshold comparison.
The need has become apparent in the microchip-tcb-capture module, which
requires a way to configure the threshold value provided by the RC
register for compare operations. To that end, a new compare component is
introduced with a helper macro COUNTER_COMP_COMPARE() to create such.
Signed-off-by: William Breathitt Gray <wbg@kernel.org>
---
William Breathitt Gray (2):
counter: Introduce the compare component
counter: microchip-tcb-capture: Add support for RC Compare
Documentation/ABI/testing/sysfs-bus-counter | 9 ++++++++
drivers/counter/microchip-tcb-capture.c | 33 +++++++++++++++++++++++++++++
include/linux/counter.h | 3 +++
3 files changed, 45 insertions(+)
---
base-commit: c2a756660324fceca26780a50950e6d91dfdc210
change-id: 20250306-introduce-compare-component-11f22ace88b1
Best regards,
--
William Breathitt Gray <wbg@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] counter: Introduce the compare component
2025-03-06 7:05 [PATCH 0/2] counter: Introduce the compare component William Breathitt Gray
@ 2025-03-06 7:05 ` William Breathitt Gray
2025-03-10 18:15 ` David Lechner
2025-03-06 7:05 ` [PATCH 2/2] counter: microchip-tcb-capture: Add support for RC Compare William Breathitt Gray
1 sibling, 1 reply; 6+ messages in thread
From: William Breathitt Gray @ 2025-03-06 7:05 UTC (permalink / raw)
To: csokas.bence, Kamel Bouhara
Cc: linux-iio, linux-kernel, linux-arm-kernel, William Breathitt Gray
Compare registers are used in devices to compare a counter channel
against a particular count value (e.g. to check if a threshold has been
reached). A macro COUNTER_COMP_COMPARE() is introduced to facilitate the
creation of compare components as Count extensions.
Signed-off-by: William Breathitt Gray <wbg@kernel.org>
---
Documentation/ABI/testing/sysfs-bus-counter | 9 +++++++++
include/linux/counter.h | 3 +++
2 files changed, 12 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-counter b/Documentation/ABI/testing/sysfs-bus-counter
index 73ac84c0bca76e013f2534efc40c0f0e8d5fb023..3e8259e56d384225ec6e952b6d5d75208f185736 100644
--- a/Documentation/ABI/testing/sysfs-bus-counter
+++ b/Documentation/ABI/testing/sysfs-bus-counter
@@ -34,6 +34,14 @@ Contact: linux-iio@vger.kernel.org
Description:
Count data of Count Y represented as a string.
+What: /sys/bus/counter/devices/counterX/countY/compare
+KernelVersion: 6.15
+Contact: linux-iio@vger.kernel.org
+Description:
+ If the counter device supports compare registers -- registers
+ used to compare counter channels against a particular count --
+ the compare count for channel Y is provided by this attribute.
+
What: /sys/bus/counter/devices/counterX/countY/capture
KernelVersion: 6.1
Contact: linux-iio@vger.kernel.org
@@ -301,6 +309,7 @@ Description:
What: /sys/bus/counter/devices/counterX/cascade_counts_enable_component_id
What: /sys/bus/counter/devices/counterX/external_input_phase_clock_select_component_id
+What: /sys/bus/counter/devices/counterX/countY/compare_component_id
What: /sys/bus/counter/devices/counterX/countY/capture_component_id
What: /sys/bus/counter/devices/counterX/countY/ceiling_component_id
What: /sys/bus/counter/devices/counterX/countY/floor_component_id
diff --git a/include/linux/counter.h b/include/linux/counter.h
index 426b7d58a438d59e5178bc5e76bac82e99737323..f208e867dd0f6995f58cf6a41c67538dad6428d0 100644
--- a/include/linux/counter.h
+++ b/include/linux/counter.h
@@ -580,6 +580,9 @@ struct counter_array {
#define COUNTER_COMP_CEILING(_read, _write) \
COUNTER_COMP_COUNT_U64("ceiling", _read, _write)
+#define COUNTER_COMP_COMPARE(_read, _write) \
+ COUNTER_COMP_COUNT_U64("compare", _read, _write)
+
#define COUNTER_COMP_COUNT_MODE(_read, _write, _available) \
{ \
.type = COUNTER_COMP_COUNT_MODE, \
--
2.48.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] counter: microchip-tcb-capture: Add support for RC Compare
2025-03-06 7:05 [PATCH 0/2] counter: Introduce the compare component William Breathitt Gray
2025-03-06 7:05 ` [PATCH 1/2] " William Breathitt Gray
@ 2025-03-06 7:05 ` William Breathitt Gray
2025-03-10 8:38 ` Csókás Bence
1 sibling, 1 reply; 6+ messages in thread
From: William Breathitt Gray @ 2025-03-06 7:05 UTC (permalink / raw)
To: csokas.bence, Kamel Bouhara
Cc: linux-iio, linux-kernel, linux-arm-kernel, William Breathitt Gray
In Capture mode, the RC register serves as a compare register for the
Timer Counter Channel. When a the Counter Value reaches the RC value, a
RC Compare event occurs (COUNTER_EVENT_THRESHOLD). This patch exposes
the RC register to userspace as the 'compare' Count extension, thus
allowing users to configure the threshold condition for these events.
Signed-off-by: William Breathitt Gray <wbg@kernel.org>
---
drivers/counter/microchip-tcb-capture.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
index 2f096a5b973d18edf5de5a2b33f2f72571deefb7..e32f8d324cb373909e0a093b14d742fa0a93e07e 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -247,6 +247,37 @@ static int mchp_tc_count_read(struct counter_device *counter,
return 0;
}
+static int mchp_tc_count_compare_read(struct counter_device *counter, struct counter_count *count,
+ u64 *val)
+{
+ struct mchp_tc_data *const priv = counter_priv(counter);
+ u32 cnt;
+ int ret;
+
+ ret = regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RC), &cnt);
+ if (ret < 0)
+ return ret;
+
+ *val = cnt;
+
+ return 0;
+}
+
+static int mchp_tc_count_compare_write(struct counter_device *counter, struct counter_count *count,
+ u64 val)
+{
+ struct mchp_tc_data *const priv = counter_priv(counter);
+
+ if (val > U32_MAX)
+ return -ERANGE;
+
+ return regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RC), val);
+}
+
+static struct counter_comp mchp_tc_count_ext[] = {
+ COUNTER_COMP_COMPARE(mchp_tc_count_compare_read, mchp_tc_count_compare_write),
+};
+
static struct counter_count mchp_tc_counts[] = {
{
.id = 0,
@@ -255,6 +286,8 @@ static struct counter_count mchp_tc_counts[] = {
.num_functions = ARRAY_SIZE(mchp_tc_count_functions),
.synapses = mchp_tc_count_synapses,
.num_synapses = ARRAY_SIZE(mchp_tc_count_synapses),
+ .ext = mchp_tc_count_ext,
+ .num_ext = ARRAY_SIZE(mchp_tc_count_ext),
},
};
--
2.48.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] counter: microchip-tcb-capture: Add support for RC Compare
2025-03-06 7:05 ` [PATCH 2/2] counter: microchip-tcb-capture: Add support for RC Compare William Breathitt Gray
@ 2025-03-10 8:38 ` Csókás Bence
2025-03-10 9:35 ` William Breathitt Gray
0 siblings, 1 reply; 6+ messages in thread
From: Csókás Bence @ 2025-03-10 8:38 UTC (permalink / raw)
To: William Breathitt Gray, Kamel Bouhara
Cc: linux-iio, linux-kernel, linux-arm-kernel
Hi,
On 2025. 03. 06. 8:05, William Breathitt Gray wrote:
> In Capture mode, the RC register serves as a compare register for the
> Timer Counter Channel. When a the Counter Value reaches the RC value, a
> RC Compare event occurs (COUNTER_EVENT_THRESHOLD). This patch exposes
> the RC register to userspace as the 'compare' Count extension, thus
> allowing users to configure the threshold condition for these events.
>
> Signed-off-by: William Breathitt Gray <wbg@kernel.org>
I'm assuming you'll merge it with my capture extensions patch. Will this
`compare` extension be carried over to 104-quad-8 as well? Otherwise:
Acked-by: Bence Csókás <csokas.bence@prolan.hu>
Bence
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] counter: microchip-tcb-capture: Add support for RC Compare
2025-03-10 8:38 ` Csókás Bence
@ 2025-03-10 9:35 ` William Breathitt Gray
0 siblings, 0 replies; 6+ messages in thread
From: William Breathitt Gray @ 2025-03-10 9:35 UTC (permalink / raw)
To: Csókás Bence
Cc: Kamel Bouhara, linux-iio, linux-kernel, linux-arm-kernel
[-- Attachment #1: Type: text/plain, Size: 1251 bytes --]
On Mon, Mar 10, 2025 at 09:38:13AM +0100, Csókás Bence wrote:
> Hi,
>
> On 2025. 03. 06. 8:05, William Breathitt Gray wrote:
> > In Capture mode, the RC register serves as a compare register for the
> > Timer Counter Channel. When a the Counter Value reaches the RC value, a
> > RC Compare event occurs (COUNTER_EVENT_THRESHOLD). This patch exposes
> > the RC register to userspace as the 'compare' Count extension, thus
> > allowing users to configure the threshold condition for these events.
> >
> > Signed-off-by: William Breathitt Gray <wbg@kernel.org>
>
> I'm assuming you'll merge it with my capture extensions patch. Will this
> `compare` extension be carried over to 104-quad-8 as well? Otherwise:
>
> Acked-by: Bence Csókás <csokas.bence@prolan.hu>
>
> Bence
Thank you for the Ack, I've merged this series now and pushed it to
counter-next.
The compare functionality is already exposed through the `preset`
component in the 104-quad-8 module, so I decided not to add a `compare`
because it felt redundant. However, I'm certain `compare` will be useful
in future drivers so that's why I want to get it merged with the rest of
the microchip-tcb-capture changes. :-)
Best regards,
William Breathitt Gray
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] counter: Introduce the compare component
2025-03-06 7:05 ` [PATCH 1/2] " William Breathitt Gray
@ 2025-03-10 18:15 ` David Lechner
0 siblings, 0 replies; 6+ messages in thread
From: David Lechner @ 2025-03-10 18:15 UTC (permalink / raw)
To: William Breathitt Gray, csokas.bence, Kamel Bouhara
Cc: linux-iio, linux-kernel, linux-arm-kernel
On 3/6/25 1:05 AM, William Breathitt Gray wrote:
...
> @@ -301,6 +309,7 @@ Description:
>
> What: /sys/bus/counter/devices/counterX/cascade_counts_enable_component_id
> What: /sys/bus/counter/devices/counterX/external_input_phase_clock_select_component_id
> +What: /sys/bus/counter/devices/counterX/countY/compare_component_id
Prefer alphabetical order?
> What: /sys/bus/counter/devices/counterX/countY/capture_component_id
> What: /sys/bus/counter/devices/counterX/countY/ceiling_component_id
> What: /sys/bus/counter/devices/counterX/countY/floor_component_id
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-03-10 18:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-06 7:05 [PATCH 0/2] counter: Introduce the compare component William Breathitt Gray
2025-03-06 7:05 ` [PATCH 1/2] " William Breathitt Gray
2025-03-10 18:15 ` David Lechner
2025-03-06 7:05 ` [PATCH 2/2] counter: microchip-tcb-capture: Add support for RC Compare William Breathitt Gray
2025-03-10 8:38 ` Csókás Bence
2025-03-10 9:35 ` William Breathitt Gray
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).