diff --git a/Documentation/devicetree/bindings/power/reset/gpio-poweroff.txt b/Documentation/devicetree/bindings/power/reset/gpio-poweroff.txt index 3e56c1b34a4c9c..76dd7b06e26a1a 100644 --- a/Documentation/devicetree/bindings/power/reset/gpio-poweroff.txt +++ b/Documentation/devicetree/bindings/power/reset/gpio-poweroff.txt @@ -31,6 +31,7 @@ Optional properties: - inactive-delay-ms: Delay (default 100) to wait after driving gpio inactive - timeout-ms: Time to wait before asserting a WARN_ON(1). If nothing is specified, 3000 ms is used. +- export : Export the GPIO line to the sysfs system Examples: diff --git a/arch/arm64/boot/dts/amlogic/overlay/Makefile b/arch/arm64/boot/dts/amlogic/overlay/Makefile index 1d9b9b7701a914..0a5bb108a6c80a 100644 --- a/arch/arm64/boot/dts/amlogic/overlay/Makefile +++ b/arch/arm64/boot/dts/amlogic/overlay/Makefile @@ -28,7 +28,8 @@ dtbo-$(CONFIG_ARCH_MESON) += \ meson-g12b-spi-b-gpioh-4-5-6-7.dtbo \ meson-g12b-uart-ao-a-gpioao-0-1.dtbo \ meson-g12b-uart-ao-b-gpioao-8-9.dtbo \ - meson-g12b-uart-ee-c-gpioh-4-5-6-7.dtbo + meson-g12b-uart-ee-c-gpioh-4-5-6-7.dtbo \ + meson-g12a-gpio-poweroff.dtbo scr-$(CONFIG_ARCH_MESON) += \ meson-fixup.scr diff --git a/arch/arm64/boot/dts/amlogic/overlay/meson-g12a-gpio-poweroff.dts b/arch/arm64/boot/dts/amlogic/overlay/meson-g12a-gpio-poweroff.dts new file mode 100644 index 00000000000000..0314500e4630a2 --- /dev/null +++ b/arch/arm64/boot/dts/amlogic/overlay/meson-g12a-gpio-poweroff.dts @@ -0,0 +1,22 @@ +/dts-v1/; +/plugin/; + +#include +#include + +/ { + compatible = "radxa,zero", "amlogic,g12a"; + + fragment@0 { + target-path = "/"; + __overlay__ { + gpio-poweroff { + compatible = "gpio-poweroff"; + /* Sets poweroff pin to GPIOAO_9 as an example. Modify as needed. */ + gpios = <&gpio_ao GPIOAO_9 GPIO_ACTIVE_LOW>; + timeout-ms = <20000>; + force; + }; + }; + }; +}; diff --git a/drivers/power/reset/gpio-poweroff.c b/drivers/power/reset/gpio-poweroff.c index 1c5af2fef1423a..81e7acb8acb5f5 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,9 +54,12 @@ 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__); @@ -74,6 +81,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 +95,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; }