aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Breathitt Gray <wbg@kernel.org>2025-03-06 16:05:44 +0900
committerWilliam Breathitt Gray <wbg@kernel.org>2025-03-10 18:20:32 +0900
commitba27a0247b7187af36cb0b1fe7f7a68067ccb555 (patch)
treef173799a173e84dad3c634726f751934dc6811af
parentcounter: Introduce the compare component (diff)
downloadlinux-rng-ba27a0247b7187af36cb0b1fe7f7a68067ccb555.tar.xz
linux-rng-ba27a0247b7187af36cb0b1fe7f7a68067ccb555.zip
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>
-rw-r--r--drivers/counter/microchip-tcb-capture.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
index aeaee6e0245e..00a463b044b5 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -302,11 +302,39 @@ static int mchp_tc_count_cap_write(struct counter_device *counter,
return ret;
}
+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 DEFINE_COUNTER_ARRAY_CAPTURE(mchp_tc_cnt_cap_array, 2);
static struct counter_comp mchp_tc_count_ext[] = {
COUNTER_COMP_ARRAY_CAPTURE(mchp_tc_count_cap_read, mchp_tc_count_cap_write,
mchp_tc_cnt_cap_array),
+ COUNTER_COMP_COMPARE(mchp_tc_count_compare_read, mchp_tc_count_compare_write),
};
static struct counter_count mchp_tc_counts[] = {