All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx@gmail.com>
To: Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Lee Jones <lee.jones@linaro.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Mark Brown <broonie@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Guenter Roeck <linux@roeck-us.net>,
	Russell King <linux@armlinux.org.uk>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Ulf Hansson <ulf.hansson@linaro.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-tegra@vger.kernel.org
Subject: [PATCH v1 4/6] mfd: max77620: Use power off call chain API
Date: Thu,  7 Oct 2021 09:02:51 +0300	[thread overview]
Message-ID: <20211007060253.17049-5-digetx@gmail.com> (raw)
In-Reply-To: <20211007060253.17049-1-digetx@gmail.com>

Use new power off call chain API which allows multiple power off handlers
to coexist. Nexus 7 Android tablet can be powered off using MAX77663 PMIC
and using a special bootloader command. At first the bootloader option
should be tried, it will have a higher priority than the PMIC.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/max77620.c       | 22 +++++++++++++++-------
 include/linux/mfd/max77620.h |  2 ++
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/max77620.c b/drivers/mfd/max77620.c
index fec2096474ad..ad40eed1f0c6 100644
--- a/drivers/mfd/max77620.c
+++ b/drivers/mfd/max77620.c
@@ -31,11 +31,10 @@
 #include <linux/init.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 
-static struct max77620_chip *max77620_scratch;
-
 static const struct resource gpio_resources[] = {
 	DEFINE_RES_IRQ(MAX77620_IRQ_TOP_GPIO),
 };
@@ -483,13 +482,17 @@ static int max77620_read_es_version(struct max77620_chip *chip)
 	return ret;
 }
 
-static void max77620_pm_power_off(void)
+static int max77620_pm_power_off(struct notifier_block *nb,
+				 unsigned long reboot_mode, void *data)
 {
-	struct max77620_chip *chip = max77620_scratch;
+	struct max77620_chip *chip = container_of(nb, struct max77620_chip,
+						  pm_off_nb);
 
 	regmap_update_bits(chip->rmap, MAX77620_REG_ONOFFCNFG1,
 			   MAX77620_ONOFFCNFG1_SFT_RST,
 			   MAX77620_ONOFFCNFG1_SFT_RST);
+
+	return NOTIFY_DONE;
 }
 
 static int max77620_probe(struct i2c_client *client,
@@ -566,9 +569,14 @@ static int max77620_probe(struct i2c_client *client,
 	}
 
 	pm_off = of_device_is_system_power_controller(client->dev.of_node);
-	if (pm_off && !pm_power_off) {
-		max77620_scratch = chip;
-		pm_power_off = max77620_pm_power_off;
+	if (pm_off) {
+		chip->pm_off_nb.notifier_call = max77620_pm_power_off;
+		chip->pm_off_nb.priority = 128;
+
+		ret = devm_register_poweroff_handler(chip->dev, &chip->pm_off_nb);
+		if (ret < 0)
+			dev_err(chip->dev,
+				"Failed to register poweroff handler: %d\n", ret);
 	}
 
 	return 0;
diff --git a/include/linux/mfd/max77620.h b/include/linux/mfd/max77620.h
index f552ef5b1100..99de4f8c9cbf 100644
--- a/include/linux/mfd/max77620.h
+++ b/include/linux/mfd/max77620.h
@@ -8,6 +8,7 @@
 #ifndef _MFD_MAX77620_H_
 #define _MFD_MAX77620_H_
 
+#include <linux/notifier.h>
 #include <linux/types.h>
 
 /* GLOBAL, PMIC, GPIO, FPS, ONOFFC, CID Registers */
@@ -327,6 +328,7 @@ enum max77620_chip_id {
 struct max77620_chip {
 	struct device *dev;
 	struct regmap *rmap;
+	struct notifier_block pm_off_nb;
 
 	int chip_irq;
 
-- 
2.32.0


  parent reply	other threads:[~2021-10-07  6:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07  6:02 [PATCH v1 0/6] Introduce power off call chain API Dmitry Osipenko
2021-10-07  6:02 ` [PATCH v1 1/6] notifier: Add blocking_notifier_call_chain_empty() Dmitry Osipenko
2021-10-07  6:02 ` [PATCH v1 2/6] kernel: Add power off handler call chain API Dmitry Osipenko
2021-10-07  6:02 ` [PATCH v1 3/6] kernel: Add devm_register_restart_handler() Dmitry Osipenko
2021-10-07  6:02 ` Dmitry Osipenko [this message]
2021-10-19 15:31   ` [PATCH v1 4/6] mfd: max77620: Use power off call chain API Lee Jones
2021-10-19 20:51     ` Dmitry Osipenko
2021-10-07  6:02 ` [PATCH v1 5/6] soc/tegra: pmc: Use devm_register_restart_handler() Dmitry Osipenko
2021-10-07  6:02 ` [PATCH v1 6/6] soc/tegra: pmc: Add power off handler Dmitry Osipenko
2021-10-07  7:18 ` [PATCH v1 0/6] Introduce power off call chain API Andy Shevchenko
2021-10-07  8:52   ` Dmitry Osipenko
2021-10-07  9:11     ` Andy Shevchenko
2021-10-07 10:11       ` Dmitry Osipenko

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=20211007060253.17049-5-digetx@gmail.com \
    --to=digetx@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=jonathanh@nvidia.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linux@roeck-us.net \
    --cc=rafael@kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=ulf.hansson@linaro.org \
    /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.