From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Philipp Zabel" <p.zabel@pengutronix.de>,
"Gregory CLEMENT" <gregory.clement@bootlin.com>,
"Michael Turquette" <mturquette@baylibre.com>,
"Stephen Boyd" <sboyd@kernel.org>,
"Rob Herring" <robh+dt@kernel.org>,
"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Thomas Bogendoerfer" <tsbogend@alpha.franken.de>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Rafał Miłecki" <rafal@milecki.pl>
Cc: "Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
<linux-mips@vger.kernel.org>, <linux-clk@vger.kernel.org>,
<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
<linux-gpio@vger.kernel.org>
Subject: Re: [PATCH v3 09/17] reset: eyeq5: add platform driver
Date: Wed, 24 Jan 2024 18:07:16 +0100 [thread overview]
Message-ID: <CYN3NQUTY1IG.165R86NIAZ46I@bootlin.com> (raw)
In-Reply-To: <82bde47d48ec2962d69d9e4edde6d6d96fcbbd65.camel@pengutronix.de>
Hi,
On Wed Jan 24, 2024 at 11:54 AM CET, Philipp Zabel wrote:
> On Di, 2024-01-23 at 19:46 +0100, Théo Lebrun wrote:
> [...]
> > diff --git a/drivers/reset/reset-eyeq5.c b/drivers/reset/reset-eyeq5.c
> > new file mode 100644
> > index 000000000000..2217e42e140b
> > --- /dev/null
> > +++ b/drivers/reset/reset-eyeq5.c
> > @@ -0,0 +1,383 @@
> [...]
>
> > +static int eq5r_assert(struct reset_controller_dev *rcdev, unsigned long id)
> > +{
> > + struct eq5r_private *priv = dev_get_drvdata(rcdev->dev);
>
> rcdev is contained in priv, you can just use container_of instead of
> chasing pointers around.
That's right. Fixed with this local macro:
#define rcdev_to_priv(rcdev) container_of(rcdev, struct eq5r_private, rcdev)
> > + u32 offset = id & GENMASK(7, 0);
> > + u32 domain = id >> 8;
> > + int ret;
> > +
> > + if (WARN_ON(domain >= EQ5R_DOMAIN_COUNT))
> > + return -EINVAL;
>
> Reset controls with domain >= EQ5R_DOMAIN_COUNT are already weeded out
> during request by of_xlate, so this check is not necessary.
It was some defensive programming. I've removed this precautionary
condition from the places it appeared.
>
> > + dev_dbg(rcdev->dev, "%u-%u: assert request\n", domain, offset);
> > +
> > + mutex_lock(&priv->mutexes[domain]);
> > + _eq5r_assert(priv, domain, offset);
> > + ret = _eq5r_busy_wait(priv, rcdev->dev, domain, offset, true);
> > + mutex_unlock(&priv->mutexes[domain]);
> > +
> > + return ret;
>
> Consider using guard(mutex)(&priv->mutexes[domain]) from
> linux/cleanup.h to automatically unlock on return.
Done. I had never used that __cleanup attr feature. It simplifies
returns.
>
> [...]
> > +static int eq5r_reset(struct reset_controller_dev *rcdev, unsigned long id)
>
> Is this used by anything? If unused, I'd prefer this not to be
> implemented. If it is used, is no delay required between assert and
> deassert by any consumer?
Not really, it follows what is done in the downstream vendor kernel.
I've had a quick look in this kernel and I don't see any consumer of
the API. For the moment I'll remove it.
>
> > +{
> > + struct device *dev = rcdev->dev;
> > + struct eq5r_private *priv = dev_get_drvdata(dev);
> > + u32 offset = id & GENMASK(7, 0);
> > + u32 domain = id >> 8;
> > + int ret;
> > +
> > + if (WARN_ON(domain >= EQ5R_DOMAIN_COUNT))
> > + return -EINVAL;
> > +
> > + dev_dbg(dev, "%u-%u: reset request\n", domain, offset);
> > +
> > + mutex_lock(&priv->mutexes[domain]);
> > +
> > + _eq5r_assert(priv, domain, offset);
> > + ret = _eq5r_busy_wait(priv, dev, domain, offset, true);
> > + if (ret) /* don't let an error disappear silently */
> > + dev_warn(dev, "%u-%u: reset assert failed: %d\n",
> > + domain, offset, ret);
>
> Why not return the error though?
The goal was to still run through the deassert even if the assert
returned an error. Goal was to address potential edge case of assert
returning an error but still taking place, in which case we want to try
to deassert to put the peripheral in a de-asserted state (as before the
call).
Not a concern anymore as the function is being removed.
>
> > + _eq5r_deassert(priv, domain, offset);
> > + ret = _eq5r_busy_wait(priv, dev, domain, offset, false);
> > +
> > + mutex_unlock(&priv->mutexes[domain]);
> > +
> > + return ret;
> > +}
> [...]
> > +static int eq5r_probe(struct platform_device *pdev)
> > +{
> > + struct device *dev = &pdev->dev;
> > + struct device_node *np = dev->of_node;
> > + struct device_node *parent_np = of_get_parent(np);
> > + struct eq5r_private *priv;
> > + int ret, i;
> > +
> > + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>
> Using devm_kzalloc() avoids leaking this on error return or driver
> unbind.
Done, thanks.
>
> > + if (!priv)
> > + return -ENOMEM;
> > +
> > + dev_set_drvdata(dev, priv);
> > +
> > + priv->olb = ERR_PTR(-ENODEV);
> > + if (parent_np) {
> > + priv->olb = syscon_node_to_regmap(parent_np);
> > + of_node_put(parent_np);
> > + }
> > + if (IS_ERR(priv->olb))
> > + return PTR_ERR(priv->olb);
> > +
> > + for (i = 0; i < EQ5R_DOMAIN_COUNT; i++)
> > + mutex_init(&priv->mutexes[i]);
> > +
> > + priv->rcdev.ops = &eq5r_ops;
> > + priv->rcdev.owner = THIS_MODULE;
> > + priv->rcdev.dev = dev;
> > + priv->rcdev.of_node = np;
> > + priv->rcdev.of_reset_n_cells = 2;
> > + priv->rcdev.of_xlate = eq5r_of_xlate;
> > +
> > + priv->rcdev.nr_resets = 0;
> > + for (i = 0; i < EQ5R_DOMAIN_COUNT; i++)
> > + priv->rcdev.nr_resets += __builtin_popcount(eq5r_valid_masks[i]);
> > +
> > + ret = reset_controller_register(&priv->rcdev);
>
> Similarly, use devm_reset_controller_register() or disable driver
> unbind with suppress_bind_attrs.
Switched to the devres version, thanks.
Thanks Philipp,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2024-01-24 17:07 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 18:46 [PATCH v3 00/17] Add support for Mobileye EyeQ5 system controller Théo Lebrun
2024-01-23 18:46 ` [PATCH v3 01/17] clk: fixed-factor: add optional accuracy support Théo Lebrun
2024-01-23 18:46 ` [PATCH v3 02/17] clk: fixed-factor: add fwname-based constructor functions Théo Lebrun
2024-01-23 18:46 ` [PATCH v3 03/17] dt-bindings: pinctrl: allow pin controller device without unit address Théo Lebrun
2024-01-23 20:57 ` Rob Herring
2024-01-23 18:46 ` [PATCH v3 04/17] dt-bindings: soc: mobileye: add EyeQ5 OLB system controller Théo Lebrun
2024-01-23 20:58 ` Rob Herring
2024-01-24 15:14 ` Rob Herring
2024-01-24 17:28 ` Théo Lebrun
2024-01-24 17:40 ` Théo Lebrun
2024-01-24 19:22 ` Rob Herring
2024-01-25 11:40 ` Théo Lebrun
2024-01-26 11:52 ` Krzysztof Kozlowski
2024-01-26 12:28 ` Théo Lebrun
2024-01-26 14:54 ` Krzysztof Kozlowski
2024-01-25 7:51 ` Krzysztof Kozlowski
2024-01-25 11:01 ` Théo Lebrun
2024-01-25 14:33 ` Andrew Davis
2024-01-25 14:49 ` Théo Lebrun
2024-01-25 15:11 ` Andrew Davis
2024-01-26 11:51 ` Krzysztof Kozlowski
2024-01-23 18:46 ` [PATCH v3 05/17] dt-bindings: clock: mobileye,eyeq5-clk: add bindings Théo Lebrun
2024-01-24 6:45 ` Krzysztof Kozlowski
2024-01-23 18:46 ` [PATCH v3 06/17] dt-bindings: reset: mobileye,eyeq5-reset: " Théo Lebrun
2024-01-24 6:47 ` Krzysztof Kozlowski
2024-01-23 18:46 ` [PATCH v3 07/17] dt-bindings: pinctrl: mobileye,eyeq5-pinctrl: " Théo Lebrun
2024-01-24 6:52 ` Krzysztof Kozlowski
2024-01-23 18:46 ` [PATCH v3 08/17] clk: eyeq5: add platform driver Théo Lebrun
2024-01-24 7:05 ` Krzysztof Kozlowski
2024-01-24 16:41 ` Théo Lebrun
2024-01-25 7:46 ` Krzysztof Kozlowski
2024-01-25 11:53 ` Théo Lebrun
2024-01-26 11:56 ` Krzysztof Kozlowski
2024-01-23 18:46 ` [PATCH v3 09/17] reset: " Théo Lebrun
2024-01-24 7:00 ` Krzysztof Kozlowski
2024-01-24 16:52 ` Théo Lebrun
2024-01-24 10:54 ` Philipp Zabel
2024-01-24 17:07 ` Théo Lebrun [this message]
2024-01-23 18:46 ` [PATCH v3 10/17] pinctrl: " Théo Lebrun
2024-01-24 7:03 ` Krzysztof Kozlowski
2024-01-24 16:55 ` Théo Lebrun
2024-01-24 15:19 ` Rob Herring
2024-01-24 17:31 ` Théo Lebrun
2024-01-23 18:46 ` [PATCH v3 11/17] MIPS: mobileye: eyeq5: rename olb@e00000 to system-controller@e00000 Théo Lebrun
2024-01-23 18:46 ` [PATCH v3 12/17] MIPS: mobileye: eyeq5: remove reg-io-width property from OLB syscon Théo Lebrun
2024-01-24 8:33 ` Sergei Shtylyov
2024-01-24 16:56 ` Théo Lebrun
2024-01-23 18:46 ` [PATCH v3 13/17] MIPS: mobileye: eyeq5: use OLB clocks controller Théo Lebrun
2024-01-23 18:46 ` [PATCH v3 14/17] MIPS: mobileye: eyeq5: add OLB reset controller node Théo Lebrun
2024-01-23 18:47 ` [PATCH v3 15/17] MIPS: mobileye: eyeq5: add reset properties to uarts Théo Lebrun
2024-01-23 18:47 ` [PATCH v3 16/17] MIPS: mobileye: eyeq5: add pinctrl nodes & pinmux function nodes Théo Lebrun
2024-01-23 18:47 ` [PATCH v3 17/17] MIPS: mobileye: eyeq5: add pinctrl properties to UART nodes Théo Lebrun
2024-01-24 6:43 ` [PATCH v3 00/17] Add support for Mobileye EyeQ5 system controller Krzysztof Kozlowski
2024-01-24 16:44 ` Théo Lebrun
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=CYN3NQUTY1IG.165R86NIAZ46I@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregory.clement@bootlin.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=p.zabel@pengutronix.de \
--cc=rafal@milecki.pl \
--cc=robh+dt@kernel.org \
--cc=sboyd@kernel.org \
--cc=tawfik.bayouk@mobileye.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tsbogend@alpha.franken.de \
--cc=vladimir.kondratiev@mobileye.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