-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel-rk3328-gpio-poweroff.patch
78 lines (71 loc) · 2.13 KB
/
kernel-rk3328-gpio-poweroff.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
diff --git a/drivers/power/reset/gpio-poweroff.c b/drivers/power/reset/gpio-poweroff.c
index 1c5af2fef..09ba6f8c6 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 (*old_power_off)(void);
static void gpio_poweroff_do_poweroff(void)
{
@@ -43,6 +44,9 @@ static void gpio_poweroff_do_poweroff(void)
/* give it some time */
mdelay(timeout);
+ if (old_power_off)
+ old_power_off();
+
WARN_ON(1);
}
@@ -50,14 +54,29 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
{
bool input = false;
enum gpiod_flags flags;
+ bool force = false;
+ bool export = false;
/* If a pm_power_off function has already been added, leave it alone */
- if (pm_power_off != NULL) {
+ force = of_property_read_bool(pdev->dev.of_node, "force");
+ if (!force && (pm_power_off != NULL)) {
dev_err(&pdev->dev,
"%s: pm_power_off function already registered\n",
__func__);
return -EBUSY;
}
+ if (pm_power_off != NULL) {
+ if (force) {
+ dev_err(&pdev->dev,
+ "%s: pm_power_off function replaced",
+ __func__);
+ } else {
+ dev_err(&pdev->dev,
+ "%s: pm_power_off function already registered",
+ __func__);
+ return -EBUSY;
+ }
+ }
input = device_property_read_bool(&pdev->dev, "input");
if (input)
@@ -74,6 +93,13 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
if (IS_ERR(reset_gpio))
return PTR_ERR(reset_gpio);
+ export = of_property_read_bool(pdev->dev.of_node, "export");
+ if (export) {
+ gpiod_export(reset_gpio, false);
+ gpiod_export_link(&pdev->dev, "poweroff-gpio", reset_gpio);
+ }
+
+ old_power_off = pm_power_off;
pm_power_off = &gpio_poweroff_do_poweroff;
return 0;
}
@@ -81,7 +107,9 @@ 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 = old_power_off;
+
+ gpiod_unexport(reset_gpio);
return 0;
}