From: "Bence Csókás" <csokas.bence@prolan.hu>
To: <linux-arm-kernel@lists.infradead.org>,
<linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: "Bence Csókás" <csokas.bence@prolan.hu>,
"Kamel Bouhara" <kamel.bouhara@bootlin.com>,
"William Breathitt Gray" <wbg@kernel.org>
Subject: [PATCH v3 2/2] counter: microchip-tcb-capture: Add capture extensions for registers RA-RC
Date: Wed, 5 Feb 2025 11:49:54 +0100 [thread overview]
Message-ID: <20250205104957.95236-3-csokas.bence@prolan.hu> (raw)
In-Reply-To: <20250205104957.95236-1-csokas.bence@prolan.hu>
TCB hardware is capable of capturing the timer value to registers RA and
RB. On top, it is capable of triggering on compare against a third
register, RC. Add these registers as extensions.
Signed-off-by: Bence Csókás <csokas.bence@prolan.hu>
---
Notes:
Changes in v2:
* Add IRQs
Changes in v3:
* Move IRQs to previous patch
drivers/counter/microchip-tcb-capture.c | 58 +++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
index fef4bb69b486..1445ac512c52 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -253,6 +253,62 @@ static int mchp_tc_count_read(struct counter_device *counter,
return 0;
}
+static int mchp_tc_count_cap_read(struct counter_device *counter,
+ struct counter_count *count, size_t idx, u64 *val)
+{
+ struct mchp_tc_data *const priv = counter_priv(counter);
+ u32 cnt;
+
+ switch (idx) {
+ case 0:
+ regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RA), &cnt);
+ break;
+ case 1:
+ regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RB), &cnt);
+ break;
+ case 2:
+ regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RC), &cnt);
+ break;
+ default:
+ return -EINVAL;
+ }
+ *val = cnt;
+
+ return 0;
+}
+
+static int mchp_tc_count_cap_write(struct counter_device *counter,
+ struct counter_count *count, size_t idx, u64 val)
+{
+ struct mchp_tc_data *const priv = counter_priv(counter);
+
+ if (val > U32_MAX)
+ return -ERANGE;
+
+ switch (idx) {
+ case 0:
+ regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RA), val);
+ break;
+ case 1:
+ regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RB), val);
+ break;
+ case 2:
+ regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RC), val);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static DEFINE_COUNTER_ARRAY_CAPTURE(mchp_tc_cnt_cap_array, 3);
+
+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),
+};
+
static struct counter_count mchp_tc_counts[] = {
{
.id = 0,
@@ -261,6 +317,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
next prev parent reply other threads:[~2025-02-05 10:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250205104957.95236-1-csokas.bence@prolan.hu>
2025-02-05 10:49 ` [PATCH v3 1/2] counter: microchip-tcb-capture: Add IRQ handling Bence Csókás
2025-02-05 10:50 ` [PATCH v3 0/2] microchip-tcb-capture: Add Capture, Compare, Overflow etc. events Bence Csókás
2025-02-06 17:32 ` Dharma.B
2025-02-07 8:12 ` [PATCH v3 1/2] counter: microchip-tcb-capture: Add IRQ handling Dharma.B
2025-02-10 9:49 ` Csókás Bence
2025-02-05 10:49 ` Bence Csókás [this message]
2025-02-07 8:19 ` [PATCH v3 2/2] counter: microchip-tcb-capture: Add capture extensions for registers RA-RC Dharma.B
2025-02-10 9:56 ` Csókás Bence
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250205104957.95236-3-csokas.bence@prolan.hu \
--to=csokas.bence@prolan.hu \
--cc=kamel.bouhara@bootlin.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wbg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®