From: Francesco Dolcini <francesco@dolcini.it>
To: Sebastian Reichel <sre@kernel.org>
Cc: Stefan Eichenberger <stefan.eichenberger@toradex.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
Francesco Dolcini <francesco.dolcini@toradex.com>
Subject: [PATCH v1 1/4] power: reset: gpio-poweroff: use a struct to store the module variables
Date: Thu, 28 Sep 2023 14:37:25 +0200 [thread overview]
Message-ID: <20230928123728.21901-1-francesco@dolcini.it> (raw)
In-Reply-To: <20230928123204.20345-1-francesco@dolcini.it>
From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
Use a struct to store the module variables. This is required to later
move to notifier_blocks where we can have several instances.
Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
---
drivers/power/reset/gpio-poweroff.c | 48 +++++++++++++++++++----------
1 file changed, 31 insertions(+), 17 deletions(-)
diff --git a/drivers/power/reset/gpio-poweroff.c b/drivers/power/reset/gpio-poweroff.c
index b28f24da1b3c..dea550e422f3 100644
--- a/drivers/power/reset/gpio-poweroff.c
+++ b/drivers/power/reset/gpio-poweroff.c
@@ -17,32 +17,37 @@
#include <linux/module.h>
#define DEFAULT_TIMEOUT_MS 3000
+
+struct gpio_poweroff {
+ struct gpio_desc *reset_gpio;
+ u32 timeout_ms;
+ u32 active_delay_ms;
+ u32 inactive_delay_ms;
+};
+
/*
* Hold configuration here, cannot be more than one instance of the driver
* since pm_power_off itself is global.
*/
-static struct gpio_desc *reset_gpio;
-static u32 timeout = DEFAULT_TIMEOUT_MS;
-static u32 active_delay = 100;
-static u32 inactive_delay = 100;
+static struct gpio_poweroff *gpio_poweroff;
static void gpio_poweroff_do_poweroff(void)
{
- BUG_ON(!reset_gpio);
+ BUG_ON(!gpio_poweroff);
/* drive it active, also inactive->active edge */
- gpiod_direction_output(reset_gpio, 1);
- mdelay(active_delay);
+ gpiod_direction_output(gpio_poweroff->reset_gpio, 1);
+ mdelay(gpio_poweroff->active_delay_ms);
/* drive inactive, also active->inactive edge */
- gpiod_set_value_cansleep(reset_gpio, 0);
- mdelay(inactive_delay);
+ gpiod_set_value_cansleep(gpio_poweroff->reset_gpio, 0);
+ mdelay(gpio_poweroff->inactive_delay_ms);
/* drive it active, also inactive->active edge */
- gpiod_set_value_cansleep(reset_gpio, 1);
+ gpiod_set_value_cansleep(gpio_poweroff->reset_gpio, 1);
/* give it some time */
- mdelay(timeout);
+ mdelay(gpio_poweroff->timeout_ms);
WARN_ON(1);
}
@@ -60,20 +65,29 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
return -EBUSY;
}
+ gpio_poweroff = devm_kzalloc(&pdev->dev, sizeof(*gpio_poweroff), GFP_KERNEL);
+ if (!gpio_poweroff)
+ return -ENOMEM;
+
input = device_property_read_bool(&pdev->dev, "input");
if (input)
flags = GPIOD_IN;
else
flags = GPIOD_OUT_LOW;
- device_property_read_u32(&pdev->dev, "active-delay-ms", &active_delay);
+
+ gpio_poweroff->active_delay_ms = 100;
+ gpio_poweroff->inactive_delay_ms = 100;
+ gpio_poweroff->timeout_ms = DEFAULT_TIMEOUT_MS;
+
+ device_property_read_u32(&pdev->dev, "active-delay-ms", &gpio_poweroff->active_delay_ms);
device_property_read_u32(&pdev->dev, "inactive-delay-ms",
- &inactive_delay);
- device_property_read_u32(&pdev->dev, "timeout-ms", &timeout);
+ &gpio_poweroff->inactive_delay_ms);
+ device_property_read_u32(&pdev->dev, "timeout-ms", &gpio_poweroff->timeout_ms);
- reset_gpio = devm_gpiod_get(&pdev->dev, NULL, flags);
- if (IS_ERR(reset_gpio))
- return PTR_ERR(reset_gpio);
+ gpio_poweroff->reset_gpio = devm_gpiod_get(&pdev->dev, NULL, flags);
+ if (IS_ERR(gpio_poweroff->reset_gpio))
+ return PTR_ERR(gpio_poweroff->reset_gpio);
pm_power_off = &gpio_poweroff_do_poweroff;
return 0;
--
2.25.1
next prev parent reply other threads:[~2023-09-28 12:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-28 12:32 [PATCH v1 0/4] power: reset: gpio-poweroff: use sys-off handler API Francesco Dolcini
2023-09-28 12:37 ` Francesco Dolcini [this message]
2023-09-28 12:37 ` [PATCH v1 2/4] " Francesco Dolcini
2023-09-28 12:37 ` [PATCH v1 3/4] dt-bindings: power: reset: gpio-poweroff: Add priority property Francesco Dolcini
2023-10-02 16:39 ` Rob Herring
2023-09-28 12:37 ` [PATCH v1 4/4] power: reset: gpio-poweroff: make sys handler priority configurable Francesco Dolcini
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=20230928123728.21901-1-francesco@dolcini.it \
--to=francesco@dolcini.it \
--cc=francesco.dolcini@toradex.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=sre@kernel.org \
--cc=stefan.eichenberger@toradex.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