linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] mfd: da9062: enable being a system-power-controller
@ 2022-04-22  6:16 Helmut Grohne
  2022-04-22  6:16 ` [PATCH v2 2/2] dt-bindings: mfd: da9062 can be a system power controller Helmut Grohne
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Helmut Grohne @ 2022-04-22  6:16 UTC (permalink / raw)
  To: Support Opensource, Lee Jones
  Cc: linux-kernel, Adam Thomson, Mark Brown, Wolfram Sang

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 | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

This series effectively is a rebased resend. The earlier posting was
https://lore.kernel.org/all/20200107120559.GA700@laureti-dev/. At that time,
Adam Thomson critisized the use of regmap and i2c inside a pm_power_off hook
since irqs are disabled. He reached out to Lee Jones, who asked Mark Brown and
Wolfram Sang, but never got any reply. I noted that a fair number of other
drivers do use regmap and i2c despite this issue. In the mean time, more
instances were added:
 * drivers/mfd/acer-ec-a500.c uses i2c
 * drivers/mfd/ntxec.c uses i2c
 * drivers/mfd/rk808.c uses regmap and i2c
Given that we proceeded with accepting the use of i2c and regmap inside
pm_power_off hooks, I think we can proceed with this patch as well.

Helmut

diff --git a/drivers/mfd/da9062-core.c b/drivers/mfd/da9062-core.c
index 2774b2cbaea6..e7af5b5f16e0 100644
--- a/drivers/mfd/da9062-core.c
+++ b/drivers/mfd/da9062-core.c
@@ -620,6 +620,23 @@ static const struct of_device_id da9062_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, da9062_dt_ids);
 
+/* Hold client since pm_power_off is global. */
+static struct i2c_client *da9062_i2c_client;
+
+static void da9062_power_off(void)
+{
+	struct da9062 *chip = i2c_get_clientdata(da9062_i2c_client);
+	const unsigned int mask = 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;
+	int ret = regmap_update_bits(chip->regmap, DA9062AA_CONTROL_A, mask, 0);
+
+	if (ret < 0)
+		dev_err(&da9062_i2c_client->dev,
+			"DA9062AA_CONTROL_A update failed, %d\n", ret);
+}
+
 static int da9062_i2c_probe(struct i2c_client *i2c,
 	const struct i2c_device_id *id)
 {
@@ -720,6 +737,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 +753,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);
 
-- 
2.20.1

Dipl.-Inf. Helmut Grohne
Research and Development
Application Engineering
 
Phone: +49 (371) 24354 0 ∙ Fax:  +49 (371) 24354 020
helmut.grohne@intenta.de ∙ https://www.intenta.de
 
Intenta GmbH ∙ Ahornstraße 55 ∙ 09112 Chemnitz, Germany
Managing Director: Dr.-Ing. Basel Fardi ∙ VAT/USt-IdNr.: DE 275745394
Commercial register: HRB 26404 Amtsgericht Chemnitz

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] dt-bindings: mfd: da9062 can be a system power controller
  2022-04-22  6:16 [PATCH v2 1/2] mfd: da9062: enable being a system-power-controller Helmut Grohne
@ 2022-04-22  6:16 ` Helmut Grohne
  2022-04-26  1:01   ` Rob Herring
  2022-04-26  9:15   ` DLG Adam Thomson
  2022-04-26  9:14 ` [PATCH v2 1/2] mfd: da9062: enable being a system-power-controller DLG Adam Thomson
  2022-06-14 20:58 ` Lee Jones
  2 siblings, 2 replies; 6+ messages in thread
From: Helmut Grohne @ 2022-04-22  6:16 UTC (permalink / raw)
  To: Support Opensource, Lee Jones, Rob Herring, Krzysztof Kozlowski,
	devicetree
  Cc: linux-kernel

The DA9062 can be used to power off a system if it is appropriately
wired.

Signed-off-by: Helmut Grohne <helmut.grohne@intenta.de>
---
 Documentation/devicetree/bindings/mfd/da9062.txt | 1 +
 1 file changed, 1 insertion(+)

This series effectively is a rebased resend. The earlier posting was
https://lore.kernel.org/all/20200107120613.GA746@laureti-dev/. Back then, this
patch was Acked-by: Rob Herring, but I'm not including that ack here, because
this patch required a non-trivial rebase.

Helmut

diff --git a/Documentation/devicetree/bindings/mfd/da9062.txt b/Documentation/devicetree/bindings/mfd/da9062.txt
index bab0d0e66cb3..4861c3ad97e9 100644
--- a/Documentation/devicetree/bindings/mfd/da9062.txt
+++ b/Documentation/devicetree/bindings/mfd/da9062.txt
@@ -41,6 +41,7 @@ further information on IRQ bindings.
 
 Optional properties:
 
+- system-power-controller
 - gpio-controller : Marks the device as a gpio controller.
 - #gpio-cells     : Should be two. The first cell is the pin number and the
                     second cell is used to specify the gpio polarity.
-- 
2.20.1

Dipl.-Inf. Helmut Grohne
Research and Development
Application Engineering
 
Phone: +49 (371) 24354 0 ∙ Fax:  +49 (371) 24354 020
helmut.grohne@intenta.de ∙ https://www.intenta.de
 
Intenta GmbH ∙ Ahornstraße 55 ∙ 09112 Chemnitz, Germany
Managing Director: Dr.-Ing. Basel Fardi ∙ VAT/USt-IdNr.: DE 275745394
Commercial register: HRB 26404 Amtsgericht Chemnitz

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] dt-bindings: mfd: da9062 can be a system power controller
  2022-04-22  6:16 ` [PATCH v2 2/2] dt-bindings: mfd: da9062 can be a system power controller Helmut Grohne
@ 2022-04-26  1:01   ` Rob Herring
  2022-04-26  9:15   ` DLG Adam Thomson
  1 sibling, 0 replies; 6+ messages in thread
From: Rob Herring @ 2022-04-26  1:01 UTC (permalink / raw)
  To: Helmut Grohne
  Cc: Support Opensource, Rob Herring, Lee Jones, devicetree,
	Krzysztof Kozlowski, linux-kernel

On Fri, 22 Apr 2022 08:16:55 +0200, Helmut Grohne wrote:
> The DA9062 can be used to power off a system if it is appropriately
> wired.
> 
> Signed-off-by: Helmut Grohne <helmut.grohne@intenta.de>
> ---
>  Documentation/devicetree/bindings/mfd/da9062.txt | 1 +
>  1 file changed, 1 insertion(+)
> 
> This series effectively is a rebased resend. The earlier posting was
> https://lore.kernel.org/all/20200107120613.GA746@laureti-dev/. Back then, this
> patch was Acked-by: Rob Herring, but I'm not including that ack here, because
> this patch required a non-trivial rebase.
> 
> Helmut
> 

Acked-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2 1/2] mfd: da9062: enable being a system-power-controller
  2022-04-22  6:16 [PATCH v2 1/2] mfd: da9062: enable being a system-power-controller Helmut Grohne
  2022-04-22  6:16 ` [PATCH v2 2/2] dt-bindings: mfd: da9062 can be a system power controller Helmut Grohne
@ 2022-04-26  9:14 ` DLG Adam Thomson
  2022-06-14 20:58 ` Lee Jones
  2 siblings, 0 replies; 6+ messages in thread
From: DLG Adam Thomson @ 2022-04-26  9:14 UTC (permalink / raw)
  To: Helmut Grohne, Support Opensource, Lee Jones
  Cc: linux-kernel, DLG Adam Thomson, Mark Brown, Wolfram Sang

On 22 April 2022 07:17, 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 | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> This series effectively is a rebased resend. The earlier posting was
> https://lore.kernel.org/all/20200107120559.GA700@laureti-dev/. At that time,
> Adam Thomson critisized the use of regmap and i2c inside a pm_power_off hook
> since irqs are disabled. He reached out to Lee Jones, who asked Mark Brown and
> Wolfram Sang, but never got any reply. I noted that a fair number of other
> drivers do use regmap and i2c despite this issue. In the mean time, more
> instances were added:
>  * drivers/mfd/acer-ec-a500.c uses i2c
>  * drivers/mfd/ntxec.c uses i2c
>  * drivers/mfd/rk808.c uses regmap and i2c
> Given that we proceeded with accepting the use of i2c and regmap inside
> pm_power_off hooks, I think we can proceed with this patch as well.
> 
> Helmut

I still have concerns, but maybe it's up to the integrator of a platform to
determine if this approach for poweroff is valid and usable, although I still
think it would be good to have checks somewhere as to whether a platform can
actually perform atmoic I2C access when IRQs are disabled. However, without
further insight right now:

Reviewed-by: Adam Thomson <DLG-Adam.Thomson.Opensource@dm.renesas.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2 2/2] dt-bindings: mfd: da9062 can be a system power controller
  2022-04-22  6:16 ` [PATCH v2 2/2] dt-bindings: mfd: da9062 can be a system power controller Helmut Grohne
  2022-04-26  1:01   ` Rob Herring
@ 2022-04-26  9:15   ` DLG Adam Thomson
  1 sibling, 0 replies; 6+ messages in thread
From: DLG Adam Thomson @ 2022-04-26  9:15 UTC (permalink / raw)
  To: Helmut Grohne, Support Opensource, Lee Jones, Rob Herring,
	Krzysztof Kozlowski, devicetree
  Cc: linux-kernel

On 22 April 2022 07:17, Helmut Grohne wrote:

> The DA9062 can be used to power off a system if it is appropriately
> wired.
> 
> Signed-off-by: Helmut Grohne <helmut.grohne@intenta.de>

Reviewed-by: Adam Thomson <DLG-Adam.Thomson.Opensource@dm.renesas.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] mfd: da9062: enable being a system-power-controller
  2022-04-22  6:16 [PATCH v2 1/2] mfd: da9062: enable being a system-power-controller Helmut Grohne
  2022-04-22  6:16 ` [PATCH v2 2/2] dt-bindings: mfd: da9062 can be a system power controller Helmut Grohne
  2022-04-26  9:14 ` [PATCH v2 1/2] mfd: da9062: enable being a system-power-controller DLG Adam Thomson
@ 2022-06-14 20:58 ` Lee Jones
  2 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2022-06-14 20:58 UTC (permalink / raw)
  To: Helmut Grohne
  Cc: Support Opensource, linux-kernel, Adam Thomson, Mark Brown, Wolfram Sang

On Fri, 22 Apr 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 | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> This series effectively is a rebased resend. The earlier posting was
> https://lore.kernel.org/all/20200107120559.GA700@laureti-dev/. At that time,
> Adam Thomson critisized the use of regmap and i2c inside a pm_power_off hook
> since irqs are disabled. He reached out to Lee Jones, who asked Mark Brown and
> Wolfram Sang, but never got any reply. I noted that a fair number of other
> drivers do use regmap and i2c despite this issue. In the mean time, more
> instances were added:
>  * drivers/mfd/acer-ec-a500.c uses i2c
>  * drivers/mfd/ntxec.c uses i2c
>  * drivers/mfd/rk808.c uses regmap and i2c
> Given that we proceeded with accepting the use of i2c and regmap inside
> pm_power_off hooks, I think we can proceed with this patch as well.
> 
> Helmut
> 
> diff --git a/drivers/mfd/da9062-core.c b/drivers/mfd/da9062-core.c
> index 2774b2cbaea6..e7af5b5f16e0 100644
> --- a/drivers/mfd/da9062-core.c
> +++ b/drivers/mfd/da9062-core.c
> @@ -620,6 +620,23 @@ static const struct of_device_id da9062_dt_ids[] = {
>  };
>  MODULE_DEVICE_TABLE(of, da9062_dt_ids);
>  
> +/* Hold client since pm_power_off is global. */

Please drop this comment.

> +static struct i2c_client *da9062_i2c_client;
> +
> +static void da9062_power_off(void)
> +{
> +	struct da9062 *chip = i2c_get_clientdata(da9062_i2c_client);
> +	const unsigned int mask = 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;
> +	int ret = regmap_update_bits(chip->regmap, DA9062AA_CONTROL_A, mask, 0);

This is messy.  Please separate declarations and assignments here.

The top one is passable.

> +	if (ret < 0)
> +		dev_err(&da9062_i2c_client->dev,
> +			"DA9062AA_CONTROL_A update failed, %d\n", ret);

You're talking to the user here.

Please use language that is more user-friendly.

> +}
> +
>  static int da9062_i2c_probe(struct i2c_client *i2c,
>  	const struct i2c_device_id *id)
>  {
> @@ -720,6 +737,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");

Do we really mind/care?

Is there anything we can do about it?

Thus, do we really need to warn() about it?

> +		}
> +	}
> +
>  	return ret;
>  }
>  
> @@ -727,6 +753,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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-06-14 20:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-22  6:16 [PATCH v2 1/2] mfd: da9062: enable being a system-power-controller Helmut Grohne
2022-04-22  6:16 ` [PATCH v2 2/2] dt-bindings: mfd: da9062 can be a system power controller Helmut Grohne
2022-04-26  1:01   ` Rob Herring
2022-04-26  9:15   ` DLG Adam Thomson
2022-04-26  9:14 ` [PATCH v2 1/2] mfd: da9062: enable being a system-power-controller DLG Adam Thomson
2022-06-14 20:58 ` Lee Jones

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).