cip-dev.lists.cip-project.org archive mirror
 help / color / mirror / Atom feed
From: Biju Das <biju.das.jz@bp.renesas.com>
To: Pavel Machek <pavel@denx.de>
Cc: "cip-dev@lists.cip-project.org" <cip-dev@lists.cip-project.org>,
	Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>,
	Chris Paterson <Chris.Paterson2@renesas.com>,
	Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>
Subject: RE: [PATCH 6.1.y-cip 5/8] counter: Add Renesas RZ/G2L MTU3a counter driver
Date: Tue, 6 Jun 2023 10:33:09 +0000	[thread overview]
Message-ID: <OS0PR01MB5922EB1CA93AD26D5320C7F28652A@OS0PR01MB5922.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <ZH8Fmom8vZ4DwxqA@duo.ucw.cz>

Hi Pavel,

> Subject: Re: [PATCH 6.1.y-cip 5/8] counter: Add Renesas RZ/G2L MTU3a
> counter driver
> 
> Hi!
> 
> > commit 0be8907359df4c62319f5cb2c6981ff0d9ebf35a upstream.
> >
> > 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.
> 
> > +static bool rz_mtu3_is_counter_invalid(struct counter_device
> > +*counter, int id) {
> > +	struct rz_mtu3_cnt *const priv = counter_priv(counter);
> > +	unsigned long tmdr;
> > +
> > +	pm_runtime_get_sync(priv->ch->dev);
> > +	tmdr = rz_mtu3_shared_reg_read(priv->ch, RZ_MTU3_TMDR3);
> > +	pm_runtime_put(priv->ch->dev);
> 
> pm_runtime_get/put is unusually fine-grained here.
> 
> Do we need error handling for pm_runtime_get?

No, it is ok. For error handing, if needed, I need to use pm_runtime_resume_and_get.

> 
> > +static int rz_mtu3_count_ceiling_write(struct counter_device
> *counter,
> > +				       struct counter_count *count,
> > +				       u64 ceiling)
> > +{
> ...
> > +	ret = rz_mtu3_lock_if_counter_is_valid(counter, ch, priv, count-
> >id);
> > +	if (ret)
> > +		return ret;
> > +
> > +	switch (count->id) {
> > +	case RZ_MTU3_16_BIT_MTU1_CH:
> > +	case RZ_MTU3_16_BIT_MTU2_CH:
> > +		if (ceiling > U16_MAX)
> > +			return -ERANGE;
> 
> Missing mutex_unlock here.

OK, will backport the patch [1]
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/counter/rz-mtu3-cnt.c?h=v6.4-rc5&id=1e28dfdf40d7293882ba7eb70a3bc0e9ab625377

> 
> > +		priv->mtu_16bit_max[ch_id] = ceiling;
> > +		break;
> > +	case RZ_MTU3_32_BIT_CH:
> > +		if (ceiling > U32_MAX)
> > +			return -ERANGE;
> 
> And here.

Same as above.

> 
> > +static int rz_mtu3_count_enable_write(struct counter_device *counter,
> > +				      struct counter_count *count, u8 enable) {
> > +	struct rz_mtu3_channel *const ch = rz_mtu3_get_ch(counter, count-
> >id);
> > +	struct rz_mtu3_cnt *const priv = counter_priv(counter);
> > +	int ret = 0;
> > +
> > +	if (enable) {
> > +		pm_runtime_get_sync(ch->dev);
> > +		mutex_lock(&priv->lock);
> > +		ret = rz_mtu3_initialize_counter(counter, count->id);
> > +		if (ret == 0)
> > +			priv->count_is_enabled[count->id] = true;
> > +		mutex_unlock(&priv->lock);
> 
> Elsewhere you did pm_runtime_get inside the lock. (Which might enable
> code cleanups).

Mutex for protecting shared resource

And

PM for register access.

Both are having different functions. Ideally, it should have
done inside the lock as you said for consistency.

> 
> > +static int rz_mtu3_cnt_probe(struct platform_device *pdev) {
> ...
> > +	mutex_init(&priv->lock);
> > +	platform_set_drvdata(pdev, priv->clk);
> > +	clk_prepare_enable(priv->clk);
> > +	pm_runtime_set_active(&pdev->dev);
> > +	pm_runtime_enable(&pdev->dev);
> > +	ret = devm_add_action_or_reset(&pdev->dev, rz_mtu3_cnt_pm_disable,
> dev);
> > +	if (ret < 0)
> > +		goto disable_clock;
> 
> Should we have dev_err_probe here?

I guess, it is not required unless there is a valid reason.

> 
> > +disable_clock:
> > +	clk_disable_unprepare(priv->clk);
> > +
> > +	return ret;
> > +}
> 
> Do we need pm_runtime_disable here?

Not required. On error case, the action_or_reset will call rz_mtu3_cnt_pm_disable.

Cheers,
Biju


  reply	other threads:[~2023-06-06 10:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-06  7:52 [PATCH 6.1.y-cip 0/8] Add MTU3 core/counter driver support for RZ/G2L alike SoCs Biju Das
2023-06-06  7:52 ` [PATCH 6.1.y-cip 1/8] clk: renesas: r9a07g044: Add MTU3a clock and reset entry Biju Das
2023-06-06  7:52 ` [PATCH 6.1.y-cip 2/8] dt-bindings: timer: Document RZ/G2L MTU3a bindings Biju Das
2023-06-06  9:35   ` Pavel Machek
2023-06-06 10:18     ` Biju Das
2023-06-06  7:52 ` [PATCH 6.1.y-cip 3/8] mfd: Add Renesas RZ/G2L MTU3a core driver Biju Das
2023-06-06  9:59   ` Pavel Machek
2023-06-06 10:11     ` Biju Das
2023-06-09 10:31       ` Pavel Machek
2023-06-09 12:19         ` Biju Das
2023-06-09 10:36   ` Pavel Machek
2023-06-12 11:38     ` Biju Das
2023-06-06  7:52 ` [PATCH 6.1.y-cip 4/8] Documentation: ABI: sysfs-bus-counter: add cascade_counts_enable and external_input_phase_clock_select Biju Das
2023-06-06 10:01   ` Pavel Machek
2023-06-06 10:19     ` Biju Das
2023-06-06  7:52 ` [PATCH 6.1.y-cip 5/8] counter: Add Renesas RZ/G2L MTU3a counter driver Biju Das
2023-06-06 10:08   ` Pavel Machek
2023-06-06 10:33     ` Biju Das [this message]
2023-06-06  7:52 ` [PATCH 6.1.y-cip 6/8] MAINTAINERS: Add entries for " Biju Das
2023-06-06  7:52 ` [PATCH 6.1.y-cip 7/8] arm64: dts: renesas: r9a07g044: Add MTU3a node Biju Das
2023-06-06  7:52 ` [PATCH 6.1.y-cip 8/8] arm64: dts: renesas: r9a07g054: " Biju Das
2023-06-06  9:15 ` [PATCH 6.1.y-cip 0/8] Add MTU3 core/counter driver support for RZ/G2L alike SoCs Pavel Machek
2023-06-06  9:17   ` Biju Das
2023-06-22 11:13 ` Pavel Machek
2023-06-22 11:42   ` 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=OS0PR01MB5922EB1CA93AD26D5320C7F28652A@OS0PR01MB5922.jpnprd01.prod.outlook.com \
    --to=biju.das.jz@bp.renesas.com \
    --cc=Chris.Paterson2@renesas.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=nobuhiro1.iwamatsu@toshiba.co.jp \
    --cc=pavel@denx.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).