diff options
Diffstat (limited to 'drivers/power/reset/gpio-poweroff.c')
-rw-r--r-- | drivers/power/reset/gpio-poweroff.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/drivers/power/reset/gpio-poweroff.c b/drivers/power/reset/gpio-poweroff.c index 06074248ba7a..e290d48ddd99 100644 --- a/drivers/power/reset/gpio-poweroff.c +++ b/drivers/power/reset/gpio-poweroff.c | |||
@@ -29,15 +29,16 @@ static int gpio_active_low; | |||
29 | 29 | ||
30 | static void gpio_poweroff_do_poweroff(void) | 30 | static void gpio_poweroff_do_poweroff(void) |
31 | { | 31 | { |
32 | BUG_ON(gpio_num == -1); | 32 | BUG_ON(!gpio_is_valid(gpio_num)); |
33 | 33 | ||
34 | /* drive it active */ | 34 | /* drive it active, also inactive->active edge */ |
35 | gpio_direction_output(gpio_num, !gpio_active_low); | 35 | gpio_direction_output(gpio_num, !gpio_active_low); |
36 | mdelay(100); | 36 | mdelay(100); |
37 | /* rising edge or drive inactive */ | 37 | /* drive inactive, also active->inactive edge */ |
38 | gpio_set_value(gpio_num, gpio_active_low); | 38 | gpio_set_value(gpio_num, gpio_active_low); |
39 | mdelay(100); | 39 | mdelay(100); |
40 | /* falling edge */ | 40 | |
41 | /* drive it active, also inactive->active edge */ | ||
41 | gpio_set_value(gpio_num, !gpio_active_low); | 42 | gpio_set_value(gpio_num, !gpio_active_low); |
42 | 43 | ||
43 | /* give it some time */ | 44 | /* give it some time */ |
@@ -60,15 +61,12 @@ static int gpio_poweroff_probe(struct platform_device *pdev) | |||
60 | } | 61 | } |
61 | 62 | ||
62 | gpio_num = of_get_gpio_flags(pdev->dev.of_node, 0, &flags); | 63 | gpio_num = of_get_gpio_flags(pdev->dev.of_node, 0, &flags); |
63 | if (gpio_num < 0) { | 64 | if (!gpio_is_valid(gpio_num)) |
64 | pr_err("%s: Could not get GPIO configuration: %d", | 65 | return gpio_num; |
65 | __func__, gpio_num); | 66 | |
66 | return -ENODEV; | ||
67 | } | ||
68 | gpio_active_low = flags & OF_GPIO_ACTIVE_LOW; | 67 | gpio_active_low = flags & OF_GPIO_ACTIVE_LOW; |
69 | 68 | ||
70 | if (of_get_property(pdev->dev.of_node, "input", NULL)) | 69 | input = of_property_read_bool(pdev->dev.of_node, "input"); |
71 | input = true; | ||
72 | 70 | ||
73 | ret = gpio_request(gpio_num, "poweroff-gpio"); | 71 | ret = gpio_request(gpio_num, "poweroff-gpio"); |
74 | if (ret) { | 72 | if (ret) { |
@@ -98,8 +96,7 @@ err: | |||
98 | 96 | ||
99 | static int gpio_poweroff_remove(struct platform_device *pdev) | 97 | static int gpio_poweroff_remove(struct platform_device *pdev) |
100 | { | 98 | { |
101 | if (gpio_num != -1) | 99 | gpio_free(gpio_num); |
102 | gpio_free(gpio_num); | ||
103 | if (pm_power_off == &gpio_poweroff_do_poweroff) | 100 | if (pm_power_off == &gpio_poweroff_do_poweroff) |
104 | pm_power_off = NULL; | 101 | pm_power_off = NULL; |
105 | 102 | ||
@@ -115,15 +112,15 @@ static struct platform_driver gpio_poweroff_driver = { | |||
115 | .probe = gpio_poweroff_probe, | 112 | .probe = gpio_poweroff_probe, |
116 | .remove = gpio_poweroff_remove, | 113 | .remove = gpio_poweroff_remove, |
117 | .driver = { | 114 | .driver = { |
118 | .name = "poweroff-gpio", | 115 | .name = "poweroff-gpio", |
119 | .owner = THIS_MODULE, | 116 | .owner = THIS_MODULE, |
120 | .of_match_table = of_gpio_poweroff_match, | 117 | .of_match_table = of_gpio_poweroff_match, |
121 | }, | 118 | }, |
122 | }; | 119 | }; |
123 | 120 | ||
124 | module_platform_driver(gpio_poweroff_driver); | 121 | module_platform_driver(gpio_poweroff_driver); |
125 | 122 | ||
126 | MODULE_AUTHOR("Jamie Lentin <jm@lentin.co.uk>"); | 123 | MODULE_AUTHOR("Jamie Lentin <jm@lentin.co.uk>"); |
127 | MODULE_DESCRIPTION("GPIO poweroff driver"); | 124 | MODULE_DESCRIPTION("GPIO poweroff driver"); |
128 | MODULE_LICENSE("GPL"); | 125 | MODULE_LICENSE("GPL v2"); |
129 | MODULE_ALIAS("platform:poweroff-gpio"); | 126 | MODULE_ALIAS("platform:poweroff-gpio"); |