mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-07 14:32:23 +00:00
power: reset: gpio-poweroff: use a struct to store the module variables
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> Link: https://lore.kernel.org/r/20231006130428.11259-2-francesco@dolcini.it Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
3f26d8b6d1
commit
13b4c69646
@ -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);
|
||||
device_property_read_u32(&pdev->dev, "inactive-delay-ms",
|
||||
&inactive_delay);
|
||||
device_property_read_u32(&pdev->dev, "timeout-ms", &timeout);
|
||||
|
||||
reset_gpio = devm_gpiod_get(&pdev->dev, NULL, flags);
|
||||
if (IS_ERR(reset_gpio))
|
||||
return PTR_ERR(reset_gpio);
|
||||
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",
|
||||
&gpio_poweroff->inactive_delay_ms);
|
||||
device_property_read_u32(&pdev->dev, "timeout-ms", &gpio_poweroff->timeout_ms);
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user