Skip to content

Commit ba27a02

Browse files
author
William Breathitt Gray
committed
counter: microchip-tcb-capture: Add support for RC Compare
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. Acked-by: Bence Csókás <csokas.bence@prolan.hu> Link: https://lore.kernel.org/r/20250306-introduce-compare-component-v1-2-93993b3dca9c@kernel.org Signed-off-by: William Breathitt Gray <wbg@kernel.org>
1 parent b519820 commit ba27a02

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

drivers/counter/microchip-tcb-capture.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,39 @@ static int mchp_tc_count_cap_write(struct counter_device *counter,
302302
return ret;
303303
}
304304

305+
static int mchp_tc_count_compare_read(struct counter_device *counter, struct counter_count *count,
306+
u64 *val)
307+
{
308+
struct mchp_tc_data *const priv = counter_priv(counter);
309+
u32 cnt;
310+
int ret;
311+
312+
ret = regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RC), &cnt);
313+
if (ret < 0)
314+
return ret;
315+
316+
*val = cnt;
317+
318+
return 0;
319+
}
320+
321+
static int mchp_tc_count_compare_write(struct counter_device *counter, struct counter_count *count,
322+
u64 val)
323+
{
324+
struct mchp_tc_data *const priv = counter_priv(counter);
325+
326+
if (val > U32_MAX)
327+
return -ERANGE;
328+
329+
return regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RC), val);
330+
}
331+
305332
static DEFINE_COUNTER_ARRAY_CAPTURE(mchp_tc_cnt_cap_array, 2);
306333

307334
static struct counter_comp mchp_tc_count_ext[] = {
308335
COUNTER_COMP_ARRAY_CAPTURE(mchp_tc_count_cap_read, mchp_tc_count_cap_write,
309336
mchp_tc_cnt_cap_array),
337+
COUNTER_COMP_COMPARE(mchp_tc_count_compare_read, mchp_tc_count_compare_write),
310338
};
311339

312340
static struct counter_count mchp_tc_counts[] = {

0 commit comments

Comments
 (0)