From: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Marcel Ziswiler <marcel.ziswiler@toradex.com>,
Jamie Lentin <jm@lentin.co.uk>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
Andrew Lunn <andrew@lunn.ch>,
Igor Opaniuk <igor.opaniuk@toradex.com>,
Oleksandr Suvorov <oleksandr.suvorov@toradex.com>,
Sebastian Reichel <sre@kernel.org>
Subject: [PATCH v2 1/2] power: reset: gpio-poweroff: add force mode
Date: Mon, 30 Sep 2019 14:12:51 +0000 [thread overview]
Message-ID: <20190930141244.12311-2-oleksandr.suvorov@toradex.com> (raw)
In-Reply-To: <20190930141244.12311-1-oleksandr.suvorov@toradex.com>
Property "force-mode" tells the driver to replace previously
initialized power-off kernel hook and allows gpio-poweroff to
probe and operate successfully in any case.
Signed-off-by: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
---
Changes in v2:
Call next pm_power_off handler if the current one
fails to power system off.
drivers/power/reset/gpio-poweroff.c | 34 ++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/drivers/power/reset/gpio-poweroff.c b/drivers/power/reset/gpio-poweroff.c
index 6a4bbb506551..94056af9ba0d 100644
--- a/drivers/power/reset/gpio-poweroff.c
+++ b/drivers/power/reset/gpio-poweroff.c
@@ -24,6 +24,7 @@ static struct gpio_desc *reset_gpio;
static u32 timeout = DEFAULT_TIMEOUT_MS;
static u32 active_delay = 100;
static u32 inactive_delay = 100;
+static void (*next_pm_power_off)(void);
static void gpio_poweroff_do_poweroff(void)
{
@@ -43,20 +44,41 @@ static void gpio_poweroff_do_poweroff(void)
/* give it some time */
mdelay(timeout);
+ /*
+ * The kernel should not reach this code. If it does, fall back to
+ * the next registered power off method.
+ */
+ if (next_pm_power_off)
+ next_pm_power_off();
+
WARN_ON(1);
}
static int gpio_poweroff_probe(struct platform_device *pdev)
{
bool input = false;
+ bool force = false;
enum gpiod_flags flags;
- /* If a pm_power_off function has already been added, leave it alone */
+
+ force = device_property_read_bool(&pdev->dev, "force-mode");
+
+ /*
+ * If a pm_power_off function has already been added, leave it alone,
+ * if force-mode is not enabled.
+ */
if (pm_power_off != NULL) {
- dev_err(&pdev->dev,
- "%s: pm_power_off function already registered",
- __func__);
- return -EBUSY;
+ if (force) {
+ dev_warn(&pdev->dev,
+ "%s: pm_power_off function replaced",
+ __func__);
+ next_pm_power_off = pm_power_off;
+ } else {
+ dev_err(&pdev->dev,
+ "%s: pm_power_off function already registered",
+ __func__);
+ return -EBUSY;
+ }
}
input = device_property_read_bool(&pdev->dev, "input");
@@ -81,7 +103,7 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
static int gpio_poweroff_remove(struct platform_device *pdev)
{
if (pm_power_off == &gpio_poweroff_do_poweroff)
- pm_power_off = NULL;
+ pm_power_off = next_pm_power_off;
return 0;
}
--
2.20.1
next prev parent reply other threads:[~2019-09-30 14:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-30 14:12 [PATCH v2 0/2] 'force-mode' for gpio-poweroff driver Oleksandr Suvorov
2019-09-30 14:12 ` Oleksandr Suvorov [this message]
2019-09-30 14:12 ` [PATCH v2 2/2] dt-bindings: power: reset: gpio-poweroff: Add 'force-mode' property Oleksandr Suvorov
2019-10-11 14:48 ` Rob Herring
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=20190930141244.12311-2-oleksandr.suvorov@toradex.com \
--to=oleksandr.suvorov@toradex.com \
--cc=andrew@lunn.ch \
--cc=igor.opaniuk@toradex.com \
--cc=jm@lentin.co.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=marcel.ziswiler@toradex.com \
--cc=sre@kernel.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 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).