From: William Breathitt Gray <william.gray@linaro.org>
To: Biju Das <biju.das.jz@bp.renesas.com>
Cc: linux-iio@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>,
Chris Paterson <chris.paterson2@renesas.com>,
Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>,
linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH v8 4/5] counter: Add Renesas RZ/G2L MTU3a counter driver
Date: Sun, 11 Dec 2022 11:38:12 -0500 [thread overview]
Message-ID: <Y5YHdKvn6AY0o9Gc@fedora> (raw)
In-Reply-To: <20221210102110.443043-5-biju.das.jz@bp.renesas.com>
[-- Attachment #1: Type: text/plain, Size: 3379 bytes --]
On Sat, Dec 10, 2022 at 10:21:09AM +0000, Biju Das wrote:
> Add RZ/G2L MTU3a counter driver. This IP supports the following
> phase counting modes on MTU1 and MTU2 channels
>
> 1) 16-bit phase counting modes on MTU1 and MTU2 channels.
> 2) 32-bit phase counting mode by cascading MTU1 and MTU2 channels.
>
> This patch adds 3 counter value channels.
> count0: 16-bit phase counter value channel on MTU1
> count1: 16-bit phase counter value channel on MTU2
> count2: 32-bit phase counter value channel by cascading
> MTU1 and MTU2 channels.
>
> The external input phase clock pin for the counter value channels
> are as follows:
> count0: "MTCLKA-MTCLKB"
> count1: "MTCLKA-MTCLKB" or "MTCLKC-MTCLKD"
> count2: "MTCLKA-MTCLKB" or "MTCLKC-MTCLKD"
>
> Use the sysfs variable "external_input_phase_clock_select" to select the
> external input phase clock pin and "cascade_counts_enable" to enable/
> disable cascading of channels.
>
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Hi Biju,
I see you use rz_mtu3_request_channel()/rz_mtu3_release_channel() to
share access to the channels between the drivers. The Counter sysfs
attributes can still be accessed when a channel is released, so should
ch->is_busy be checked before every Counter callback to ensure we do not
try to access a busy channel?
> +static inline struct rz_mtu3_channel *
> +rz_mtu3_get_ch(struct counter_device *counter, int id)
I'm not sure why this is split between two lines but you can put it all
on one.
> +static void rz_mtu3_32bit_cnt_setting(struct counter_device *counter, int id)
It doesn't look like you're using the 'id' parameter in this function so
you might as well remove it.
> + switch (id) {
> + case RZ_MTU3_16_BIT_MTU1_CH:
> + case RZ_MTU3_16_BIT_MTU2_CH:
> + if (!rz_mtu3_request_channel(ch))
> + return -EBUSY;
> +
> + rz_mtu3_16bit_cnt_setting(counter, id);
> +
> + break;
> + case RZ_MTU3_32_BIT_CH:
> + /*
> + * 32-bit phase counting need MTU1 and MTU2 to create 32-bit
> + * cascade counter.
> + */
> + if (!rz_mtu3_request_channel(ch1))
> + return -EBUSY;
> +
> + if (!rz_mtu3_request_channel(ch2)) {
> + rz_mtu3_release_channel(ch1);
> + return -EBUSY;
> + }
> +
> + rz_mtu3_32bit_cnt_setting(counter, id);
> + break;
> + default:
> + /* should never reach this path */
> + return -EINVAL;
> + }
> +
> + return 0;
Instead of the two 'break' statements in the switch block above, replace
them both with 'return 0' and then you can get rid of this 'return 0'
at the end.
> + if ((mtclkc_mtclkd && (synapse->signal->id == SIGNAL_A_ID ||
> + synapse->signal->id == SIGNAL_B_ID)) ||
> + (!mtclkc_mtclkd && (synapse->signal->id == SIGNAL_C_ID ||
> + synapse->signal->id == SIGNAL_D_ID))) {
That's a lot of expressions to evaluate, so it's easy for someone to get
lost in what's happening here. It'll be good to refactor by spinning off
the signal check to a bool variable. For example:
const bool is_signal_ab = (synapse->signal->id == SIGNAL_A_ID) ||
(synapse->signal->id == SIGNAL_B_ID);
...
if ((mtclkc_mtclkd && is_signal_ab) ||
(!mtclkc_mtclkd && !is_signal_ab)) {
mutex_unlock(&priv->lock
return 0;
}
William Breathitt Gray
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2022-12-11 20:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-10 10:21 [PATCH v8 0/5] Add RZ/G2L MTU3a Core, Counter and pwm driver Biju Das
2022-12-10 10:21 ` [PATCH v8 1/5] dt-bindings: timer: Document RZ/G2L MTU3a bindings Biju Das
2022-12-10 10:21 ` [PATCH v8 2/5] clocksource/drivers: Add Renesas RZ/G2L MTU3a core driver Biju Das
2022-12-10 10:21 ` [PATCH v8 3/5] Documentation: ABI: sysfs-bus-counter: add cascade_counts_enable and external_input_phase_clock_select Biju Das
2022-12-11 15:34 ` William Breathitt Gray
2022-12-11 16:12 ` Biju Das
2022-12-11 15:46 ` William Breathitt Gray
2022-12-10 10:21 ` [PATCH v8 4/5] counter: Add Renesas RZ/G2L MTU3a counter driver Biju Das
2022-12-11 16:38 ` William Breathitt Gray [this message]
2022-12-12 11:37 ` Biju Das
2022-12-10 10:21 ` [PATCH v8 5/5] pwm: Add Renesas RZ/G2L MTU3a PWM driver Biju Das
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=Y5YHdKvn6AY0o9Gc@fedora \
--to=william.gray@linaro.org \
--cc=biju.das.jz@bp.renesas.com \
--cc=chris.paterson2@renesas.com \
--cc=geert+renesas@glider.be \
--cc=linux-iio@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.