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
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
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
© 2016 - 2026 Red Hat, Inc.