|
@@ -15,31 +15,29 @@
|
|
#include <linux/init.h>
|
|
#include <linux/init.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/platform_device.h>
|
|
-#include <linux/gpio.h>
|
|
|
|
|
|
+#include <linux/gpio/consumer.h>
|
|
#include <linux/of_platform.h>
|
|
#include <linux/of_platform.h>
|
|
-#include <linux/of_gpio.h>
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/module.h>
|
|
|
|
|
|
/*
|
|
/*
|
|
* Hold configuration here, cannot be more than one instance of the driver
|
|
* Hold configuration here, cannot be more than one instance of the driver
|
|
* since pm_power_off itself is global.
|
|
* since pm_power_off itself is global.
|
|
*/
|
|
*/
|
|
-static int gpio_num = -1;
|
|
|
|
-static int gpio_active_low;
|
|
|
|
|
|
+static struct gpio_desc *reset_gpio;
|
|
|
|
|
|
static void gpio_poweroff_do_poweroff(void)
|
|
static void gpio_poweroff_do_poweroff(void)
|
|
{
|
|
{
|
|
- BUG_ON(!gpio_is_valid(gpio_num));
|
|
|
|
|
|
+ BUG_ON(!reset_gpio);
|
|
|
|
|
|
/* drive it active, also inactive->active edge */
|
|
/* drive it active, also inactive->active edge */
|
|
- gpio_direction_output(gpio_num, !gpio_active_low);
|
|
|
|
|
|
+ gpiod_direction_output(reset_gpio, 1);
|
|
mdelay(100);
|
|
mdelay(100);
|
|
/* drive inactive, also active->inactive edge */
|
|
/* drive inactive, also active->inactive edge */
|
|
- gpio_set_value(gpio_num, gpio_active_low);
|
|
|
|
|
|
+ gpiod_set_value(reset_gpio, 0);
|
|
mdelay(100);
|
|
mdelay(100);
|
|
|
|
|
|
/* drive it active, also inactive->active edge */
|
|
/* drive it active, also inactive->active edge */
|
|
- gpio_set_value(gpio_num, !gpio_active_low);
|
|
|
|
|
|
+ gpiod_set_value(reset_gpio, 1);
|
|
|
|
|
|
/* give it some time */
|
|
/* give it some time */
|
|
mdelay(3000);
|
|
mdelay(3000);
|
|
@@ -49,54 +47,42 @@ static void gpio_poweroff_do_poweroff(void)
|
|
|
|
|
|
static int gpio_poweroff_probe(struct platform_device *pdev)
|
|
static int gpio_poweroff_probe(struct platform_device *pdev)
|
|
{
|
|
{
|
|
- enum of_gpio_flags flags;
|
|
|
|
bool input = false;
|
|
bool input = false;
|
|
- int ret;
|
|
|
|
|
|
|
|
/* If a pm_power_off function has already been added, leave it alone */
|
|
/* If a pm_power_off function has already been added, leave it alone */
|
|
if (pm_power_off != NULL) {
|
|
if (pm_power_off != NULL) {
|
|
- pr_err("%s: pm_power_off function already registered",
|
|
|
|
|
|
+ dev_err(&pdev->dev,
|
|
|
|
+ "%s: pm_power_off function already registered",
|
|
__func__);
|
|
__func__);
|
|
return -EBUSY;
|
|
return -EBUSY;
|
|
}
|
|
}
|
|
|
|
|
|
- gpio_num = of_get_gpio_flags(pdev->dev.of_node, 0, &flags);
|
|
|
|
- if (!gpio_is_valid(gpio_num))
|
|
|
|
- return gpio_num;
|
|
|
|
-
|
|
|
|
- gpio_active_low = flags & OF_GPIO_ACTIVE_LOW;
|
|
|
|
|
|
+ reset_gpio = devm_gpiod_get(&pdev->dev, NULL);
|
|
|
|
+ if (IS_ERR(reset_gpio))
|
|
|
|
+ return PTR_ERR(reset_gpio);
|
|
|
|
|
|
input = of_property_read_bool(pdev->dev.of_node, "input");
|
|
input = of_property_read_bool(pdev->dev.of_node, "input");
|
|
|
|
|
|
- ret = gpio_request(gpio_num, "poweroff-gpio");
|
|
|
|
- if (ret) {
|
|
|
|
- pr_err("%s: Could not get GPIO %d", __func__, gpio_num);
|
|
|
|
- return ret;
|
|
|
|
- }
|
|
|
|
if (input) {
|
|
if (input) {
|
|
- if (gpio_direction_input(gpio_num)) {
|
|
|
|
- pr_err("Could not set direction of GPIO %d to input",
|
|
|
|
- gpio_num);
|
|
|
|
- goto err;
|
|
|
|
|
|
+ if (gpiod_direction_input(reset_gpio)) {
|
|
|
|
+ dev_err(&pdev->dev,
|
|
|
|
+ "Could not set direction of reset GPIO to input\n");
|
|
|
|
+ return -ENODEV;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- if (gpio_direction_output(gpio_num, gpio_active_low)) {
|
|
|
|
- pr_err("Could not set direction of GPIO %d", gpio_num);
|
|
|
|
- goto err;
|
|
|
|
|
|
+ if (gpiod_direction_output(reset_gpio, 0)) {
|
|
|
|
+ dev_err(&pdev->dev,
|
|
|
|
+ "Could not set direction of reset GPIO\n");
|
|
|
|
+ return -ENODEV;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
pm_power_off = &gpio_poweroff_do_poweroff;
|
|
pm_power_off = &gpio_poweroff_do_poweroff;
|
|
return 0;
|
|
return 0;
|
|
-
|
|
|
|
-err:
|
|
|
|
- gpio_free(gpio_num);
|
|
|
|
- return -ENODEV;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
static int gpio_poweroff_remove(struct platform_device *pdev)
|
|
static int gpio_poweroff_remove(struct platform_device *pdev)
|
|
{
|
|
{
|
|
- gpio_free(gpio_num);
|
|
|
|
if (pm_power_off == &gpio_poweroff_do_poweroff)
|
|
if (pm_power_off == &gpio_poweroff_do_poweroff)
|
|
pm_power_off = NULL;
|
|
pm_power_off = NULL;
|
|
|
|
|