From: William Breathitt Gray <wbg@kernel.org>
To: Wadim Mueller <wafgo01@gmail.com>
Cc: William Breathitt Gray <wbg@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Rob Herring <robh@kernel.org>, Conor Dooley <conor+dt@kernel.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 2/3] counter: add GPIO-based counter driver
Date: Thu, 23 Jul 2026 01:00:40 +0900 [thread overview]
Message-ID: <20260722160042.855724-1-wbg@kernel.org> (raw)
In-Reply-To: <20260722114936.849882-1-wbg@kernel.org>
On Wed, Jul 22, 2026 at 08:49:34PM +0900, William Breathitt Gray wrote:
> On Tue, Jul 14, 2026 at 10:17:08AM +0200, Wadim Mueller wrote:
> > +static int gpio_counter_setup_signals(struct gpio_counter_priv *priv)
> > +{
> > + priv->signals[GPIO_COUNTER_SIGNAL_A].id = GPIO_COUNTER_SIGNAL_A;
> > + priv->signals[GPIO_COUNTER_SIGNAL_A].name = "Signal A";
> > + priv->signals[GPIO_COUNTER_SIGNAL_B].id = GPIO_COUNTER_SIGNAL_B;
> > + priv->signals[GPIO_COUNTER_SIGNAL_B].name = "Signal B";
> > +
> > + if (priv->count_priv[GPIO_COUNTER_COUNT_1].has_index) {
> > + priv->signals[GPIO_COUNTER_SIGNAL_INDEX1].id =
> > + GPIO_COUNTER_SIGNAL_INDEX1;
> > + priv->signals[GPIO_COUNTER_SIGNAL_INDEX1].name = "Index 1";
> > + }
> > + if (priv->count_priv[GPIO_COUNTER_COUNT_2].has_index) {
> > + priv->signals[GPIO_COUNTER_SIGNAL_INDEX2].id =
> > + GPIO_COUNTER_SIGNAL_INDEX2;
> > + priv->signals[GPIO_COUNTER_SIGNAL_INDEX2].name = "Index 2";
> > + }
> > +
> > + return 2 + priv->count_priv[GPIO_COUNTER_COUNT_1].has_index +
> > + priv->count_priv[GPIO_COUNTER_COUNT_2].has_index;
>
> As sashiko-bot pointed out, the Counter subsystem doesn't handle gaps in
> the signals array. What you can try instead is use a local variable
> num_signals to hold the current signals array offset:
>
> num_signals = 2;
> if (priv->count_priv[GPIO_COUNTER_COUNT_1].has_index) {
> priv->signals[i].id = GPIO_COUNTER_SIGNAL_INDEX1;
> priv->signals[i].name = "Index 1";
> i++;
> }
> if (priv->count_priv[GPIO_COUNTER_COUNT_2].has_index) {
> priv->signals[i].id = GPIO_COUNTER_SIGNAL_INDEX2;
> priv->signals[i].name = "Index 2";
> i++;
> }
>
> return i;
Oops, I intended for those 'i' to be 'num_signals'. However, if you like
you may name it 'i' or whatever makes sense.
>
> Now, to refer back to the correct signals element later you have three
> options: loop through the signals array and check each id, or save the
> signals offset to a member of count_priv so you can refer to it later.
>
> I think the first option is the simplest because there are only two
> Index Signals and a single if statement suffices: if priv->signals[2].id
> is not GPIO_COUNTER_SIGNAL_INDEX1, then it is GPIO_COUNTER_SIGNAL_INDEX2
> (and vice versa).
>
> > +}
> > +
> > +static int gpio_counter_setup_synapses(struct gpio_counter_priv *priv)
> > +{
> > + int n_c1 = 2, n_c2 = 1;
> > +
> > + priv->synapses_count1[0].actions_list = gpio_counter_synapse_actions;
> > + priv->synapses_count1[0].num_actions =
> > + ARRAY_SIZE(gpio_counter_synapse_actions);
> > + priv->synapses_count1[0].signal = &priv->signals[GPIO_COUNTER_SIGNAL_A];
> > +
> > + priv->synapses_count1[1].actions_list = gpio_counter_synapse_actions;
> > + priv->synapses_count1[1].num_actions =
> > + ARRAY_SIZE(gpio_counter_synapse_actions);
> > + priv->synapses_count1[1].signal = &priv->signals[GPIO_COUNTER_SIGNAL_B];
> > +
> > + if (priv->count_priv[GPIO_COUNTER_COUNT_1].has_index) {
> > + priv->synapses_count1[2].actions_list =
> > + gpio_counter_index_synapse_actions;
> > + priv->synapses_count1[2].num_actions =
> > + ARRAY_SIZE(gpio_counter_index_synapse_actions);
> > + priv->synapses_count1[2].signal =
> > + &priv->signals[GPIO_COUNTER_SIGNAL_INDEX1];
>
> You can use a ternary directly like this:
>
> priv->synapses_count1[2].signal = (priv->signals[2].id == GPIO_COUNTER_SIGNAL_INDEX1)
> ? &priv->signals[2] : &priv->signals[3];
I suppose index1 would always be at offset 2 if it does exist, so this
ternary isn't needed here but rather better for the index2 case in the
count2 block.
William Breathitt Gray
next prev parent reply other threads:[~2026-07-22 16:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 8:17 [PATCH v7 0/3] counter: add GPIO-based counter driver Wadim Mueller
2026-07-14 8:17 ` [PATCH v7 1/3] dt-bindings: counter: add gpio-counter binding Wadim Mueller
2026-07-22 15:42 ` Rob Herring
2026-07-14 8:17 ` [PATCH v7 2/3] counter: add GPIO-based counter driver Wadim Mueller
2026-07-14 8:27 ` sashiko-bot
2026-07-14 12:20 ` Uwe Kleine-König
2026-07-22 11:49 ` William Breathitt Gray
2026-07-22 16:00 ` William Breathitt Gray [this message]
2026-07-14 8:17 ` [PATCH v7 3/3] MAINTAINERS: add entry for GPIO " Wadim Mueller
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=20260722160042.855724-1-wbg@kernel.org \
--to=wbg@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=wafgo01@gmail.com \
/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