Skip to content

Commit 13b4c69

Browse files
eichenbergersre
authored andcommitted
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>
1 parent 3f26d8b commit 13b4c69

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

drivers/power/reset/gpio-poweroff.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,37 @@
1717
#include <linux/module.h>
1818

1919
#define DEFAULT_TIMEOUT_MS 3000
20+
21+
struct gpio_poweroff {
22+
struct gpio_desc *reset_gpio;
23+
u32 timeout_ms;
24+
u32 active_delay_ms;
25+
u32 inactive_delay_ms;
26+
};
27+
2028
/*
2129
* Hold configuration here, cannot be more than one instance of the driver
2230
* since pm_power_off itself is global.
2331
*/
24-
static struct gpio_desc *reset_gpio;
25-
static u32 timeout = DEFAULT_TIMEOUT_MS;
26-
static u32 active_delay = 100;
27-
static u32 inactive_delay = 100;
32+
static struct gpio_poweroff *gpio_poweroff;
2833

2934
static void gpio_poweroff_do_poweroff(void)
3035
{
31-
BUG_ON(!reset_gpio);
36+
BUG_ON(!gpio_poweroff);
3237

3338
/* drive it active, also inactive->active edge */
34-
gpiod_direction_output(reset_gpio, 1);
35-
mdelay(active_delay);
39+
gpiod_direction_output(gpio_poweroff->reset_gpio, 1);
40+
mdelay(gpio_poweroff->active_delay_ms);
3641

3742
/* drive inactive, also active->inactive edge */
38-
gpiod_set_value_cansleep(reset_gpio, 0);
39-
mdelay(inactive_delay);
43+
gpiod_set_value_cansleep(gpio_poweroff->reset_gpio, 0);
44+
mdelay(gpio_poweroff->inactive_delay_ms);
4045

4146
/* drive it active, also inactive->active edge */
42-
gpiod_set_value_cansleep(reset_gpio, 1);
47+
gpiod_set_value_cansleep(gpio_poweroff->reset_gpio, 1);
4348

4449
/* give it some time */
45-
mdelay(timeout);
50+
mdelay(gpio_poweroff->timeout_ms);
4651

4752
WARN_ON(1);
4853
}
@@ -60,20 +65,29 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
6065
return -EBUSY;
6166
}
6267

68+
gpio_poweroff = devm_kzalloc(&pdev->dev, sizeof(*gpio_poweroff), GFP_KERNEL);
69+
if (!gpio_poweroff)
70+
return -ENOMEM;
71+
6372
input = device_property_read_bool(&pdev->dev, "input");
6473
if (input)
6574
flags = GPIOD_IN;
6675
else
6776
flags = GPIOD_OUT_LOW;
6877

69-
device_property_read_u32(&pdev->dev, "active-delay-ms", &active_delay);
78+
79+
gpio_poweroff->active_delay_ms = 100;
80+
gpio_poweroff->inactive_delay_ms = 100;
81+
gpio_poweroff->timeout_ms = DEFAULT_TIMEOUT_MS;
82+
83+
device_property_read_u32(&pdev->dev, "active-delay-ms", &gpio_poweroff->active_delay_ms);
7084
device_property_read_u32(&pdev->dev, "inactive-delay-ms",
71-
&inactive_delay);
72-
device_property_read_u32(&pdev->dev, "timeout-ms", &timeout);
85+
&gpio_poweroff->inactive_delay_ms);
86+
device_property_read_u32(&pdev->dev, "timeout-ms", &gpio_poweroff->timeout_ms);
7387

74-
reset_gpio = devm_gpiod_get(&pdev->dev, NULL, flags);
75-
if (IS_ERR(reset_gpio))
76-
return PTR_ERR(reset_gpio);
88+
gpio_poweroff->reset_gpio = devm_gpiod_get(&pdev->dev, NULL, flags);
89+
if (IS_ERR(gpio_poweroff->reset_gpio))
90+
return PTR_ERR(gpio_poweroff->reset_gpio);
7791

7892
pm_power_off = &gpio_poweroff_do_poweroff;
7993
return 0;

0 commit comments

Comments
 (0)