linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: Helmut Grohne <helmut.grohne@intenta.de>
Cc: Support Opensource <support.opensource@diasemi.com>,
	linux-kernel@vger.kernel.org,
	Adam Thomson <Adam.Thomson.Opensource@diasemi.com>,
	Mark Brown <broonie@kernel.org>, Wolfram Sang <wsa@the-dreams.de>
Subject: Re: [PATCH v3 1/2] mfd: da9062: enable being a system-power-controller
Date: Mon, 4 Jul 2022 11:27:02 +0100	[thread overview]
Message-ID: <YsLAdjpBIYBda1Dv@google.com> (raw)
In-Reply-To: <bafccf43111a24e20fb36c46740d650dedda04c0.1656418366.git.helmut.grohne@intenta.de>

On Tue, 28 Jun 2022, Helmut Grohne wrote:

> The DA9062 can be the device used to power the CPU. In that case, it can
> be used to power off the system. In the CONTROL_A register, the M_*_EN
> bits must be zero for the corresponding *_EN bits to have an effect. We
> zero them all to turn off the system.
> 
> Signed-off-by: Helmut Grohne <helmut.grohne@intenta.de>
> ---
>  drivers/mfd/da9062-core.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> Compared to v2, this addresses the following concerns raised by Lee Jones:
>  * Drop unnecessary comment.
>  * Restructure da9062_power_off to avoid unnecessary assignments.
>  * Make power off failure message user friendly while still including
>    the error code for diagnostics.
> 
> Lee Jones also questioned the utility of warning about pm_power_off already
> being assigned:
> 
> > Do we really mind/care?
> >
> > Is there anything we can do about it?
> >
> > Thus, do we really need to warn() about it?
> 
> I do think this is useful, because it only happens when two nodes decalare
> being a system-power-controller. It is a misconfiguration of your device tree
> that is being warned here. Other drivers (e.g. rn5t618.c, act8865-regulator.c,
> rtc-jz4740.c, and bcm2835_wdt.c) issue a similar warning.
> 
> I note that Adam Thomson reviewed v2. Thank you. I did not include the
> Reviewed-by, because noticeable code changed compared to what was reviewed.
> 
> As pointed out by Adam Thomson, this version still uses regmap (and possibly
> mutexes) in pm_power_off (with irqs disabled). This is a fundamental problem
> shared with many other pm_power_off hooks.
> 
> I've now included Rob Herring's Acked-by on the second patch as the rebase was
> trivial.
> 
> Helmut
> diff --git a/drivers/mfd/da9062-core.c b/drivers/mfd/da9062-core.c
> index 2774b2cbaea6..0083a2756f28 100644
> --- a/drivers/mfd/da9062-core.c
> +++ b/drivers/mfd/da9062-core.c
> @@ -620,6 +620,26 @@ static const struct of_device_id da9062_dt_ids[] = {
>  };
>  MODULE_DEVICE_TABLE(of, da9062_dt_ids);
>  
> +static struct i2c_client *da9062_i2c_client;
> +
> +static void da9062_power_off(void)
> +{
> +	int ret;
> +
> +	ret = regmap_update_bits(
> +		((struct
> da9062*)i2c_get_clientdata(da9062_i2c_client))->regmap,

This is ugly.  Please pull this out of the function args and separate
the whole thing.  No func()->attribute craziness please.

> +		DA9062AA_CONTROL_A,
> +		DA9062AA_SYSTEM_EN_MASK | DA9062AA_POWER_EN_MASK |
> +			DA9062AA_POWER1_EN_MASK | DA9062AA_M_SYSTEM_EN_MASK |
> +			DA9062AA_M_POWER_EN_MASK | DA9062AA_M_POWER1_EN_MASK,
> +		0
> +	);
> +
> +	if (ret < 0)
> +		dev_err(&da9062_i2c_client->dev,
> +			"failed to power the system off (err=%d)\n", ret);

Either start with a uppercase char, or don't.  Please be consistent.

> +}
> +
>  static int da9062_i2c_probe(struct i2c_client *i2c,
>  	const struct i2c_device_id *id)
>  {
> @@ -720,6 +740,15 @@ static int da9062_i2c_probe(struct i2c_client *i2c,
>  		return ret;
>  	}
>  
> +	if (of_device_is_system_power_controller(i2c->dev.of_node)) {
> +		if (!pm_power_off) {
> +			da9062_i2c_client = i2c;
> +			pm_power_off = da9062_power_off;
> +		} else {
> +			dev_warn(&i2c->dev, "Poweroff callback already assigned\n");
> +		}
> +	}
> +
>  	return ret;
>  }
>  
> @@ -727,6 +756,11 @@ static int da9062_i2c_remove(struct i2c_client *i2c)
>  {
>  	struct da9062 *chip = i2c_get_clientdata(i2c);
>  
> +	if (pm_power_off == da9062_power_off)
> +		pm_power_off = NULL;
> +	if (da9062_i2c_client)
> +		da9062_i2c_client = NULL;
> +
>  	mfd_remove_devices(chip->dev);
>  	regmap_del_irq_chip(i2c->irq, chip->regmap_irq);
>  

-- 
Lee Jones [李琼斯]
Principal Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

      parent reply	other threads:[~2022-07-04 10:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28 12:45 [PATCH v3 1/2] mfd: da9062: enable being a system-power-controller Helmut Grohne
2022-06-28 12:45 ` [PATCH v3 2/2] dt-bindings: mfd: da9062 can be a system power controller Helmut Grohne
2022-07-04 10:27 ` Lee Jones [this message]

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=YsLAdjpBIYBda1Dv@google.com \
    --to=lee.jones@linaro.org \
    --cc=Adam.Thomson.Opensource@diasemi.com \
    --cc=broonie@kernel.org \
    --cc=helmut.grohne@intenta.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=support.opensource@diasemi.com \
    --cc=wsa@the-dreams.de \
    /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).