diff mbox

[3/4] Power: Reset: Power off by restarting

Message ID 1356697512-3950-4-git-send-email-andrew@lunn.ch (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Lunn Dec. 28, 2012, 12:25 p.m. UTC
Some devices, Buffalo Linkstation LS-XHL and LS-CHLv2 for example,
power-off by restarting to letting u-boot hold the SoC until the user
presses a key. Add a generic driver to implement this. It binds a
function to pm_power_off, which calls arm_pm_restart.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 .../bindings/power_supply/restart-poweroff.txt     |    9 +++
 drivers/power/reset/Kconfig                        |    8 +++
 drivers/power/reset/Makefile                       |    1 +
 drivers/power/reset/restart-poweroff.c             |   67 ++++++++++++++++++++
 4 files changed, 85 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power_supply/restart-poweroff.txt
 create mode 100644 drivers/power/reset/restart-poweroff.c

Comments

Michael Walle Dec. 28, 2012, 6:59 p.m. UTC | #1
Am Freitag 28 Dezember 2012, 13:25:11 schrieb Andrew Lunn:
> Some devices, Buffalo Linkstation LS-XHL and LS-CHLv2 for example,
> power-off by restarting to letting u-boot hold the SoC until the user
> presses a key. Add a generic driver to implement this. It binds a
> function to pm_power_off, which calls arm_pm_restart.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>  .../bindings/power_supply/restart-poweroff.txt     |    9 +++
>  drivers/power/reset/Kconfig                        |    8 +++
>  drivers/power/reset/Makefile                       |    1 +
>  drivers/power/reset/restart-poweroff.c             |   67
> ++++++++++++++++++++ 4 files changed, 85 insertions(+)
>  create mode 100644
> Documentation/devicetree/bindings/power_supply/restart-poweroff.txt create
> mode 100644 drivers/power/reset/restart-poweroff.c
> 
> diff --git
> a/Documentation/devicetree/bindings/power_supply/restart-poweroff.txt
> b/Documentation/devicetree/bindings/power_supply/restart-poweroff.txt new
> file mode 100644
> index 0000000..e4f1660
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power_supply/restart-poweroff.txt
> @@ -0,0 +1,9 @@
> +* Restart Power Off
> +
> +Buffalo Linkstation LS-XHL and LS-CHLv2, and other devices power off
> +by restarting and letting u-boot keep hold of the machine until the
> +user presses a button.
> +
> +Required Properties:
> +- compatible: Should be "restart-poweroff"
> +
> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> index 6453aac..1ae65b8 100644
> --- a/drivers/power/reset/Kconfig
> +++ b/drivers/power/reset/Kconfig
> @@ -22,3 +22,11 @@ config POWER_RESET_QNAP
>  	  commands to the microcontroller which controls the main power.
> 
>  	  Say Y if you have a QNAP NAS.
> +
> +config POWER_RESET_RESTART
> +	bool "Restart power-off driver"
> +	depends on ARM
> +	help
> +	  Some boards don't actually have the ability to power off.
> +	  Instead they restart, and u-boot holds the SoC until the
> +	  user presses a key. u-boot then boots into Linux.
> diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
> index c4d3b2d..0f317f5 100644
> --- a/drivers/power/reset/Makefile
> +++ b/drivers/power/reset/Makefile
> @@ -1,2 +1,3 @@
>  obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
>  obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o
> +obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o
> \ No newline at end of file
> diff --git a/drivers/power/reset/restart-poweroff.c
> b/drivers/power/reset/restart-poweroff.c new file mode 100644
> index 0000000..79b1a2e
> --- /dev/null
> +++ b/drivers/power/reset/restart-poweroff.c
> @@ -0,0 +1,67 @@
> +/*
> + * Power off by restarting and let u-boot keep hold of the machine
> + * until the user presses a button for example.
> + *
> + * Andrew Lunn <andrew@lunn.ch>
> + *
> + * Copyright (C) 2012 Andrew Lunn
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + */
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/platform_device.h>
> +#include <asm/system_misc.h>
> +#include <linux/of_platform.h>
> +#include <linux/module.h>
> +
> +static void restart_poweroff_do_poweroff(void)
> +{
> +	arm_pm_restart('h', NULL);
> +}
> +
> +static int __devinit restart_poweroff_probe(struct platform_device *pdev)
> +{
> +	/* If a pm_power_off function has already been added, leave it alone 
*/
> +	if (pm_power_off != NULL) {
> +		dev_err(&pdev->dev,
> +			"pm_power_off function already registered");
> +		return -EBUSY;
> +	}
> +
> +	pm_power_off = &restart_poweroff_do_poweroff;
> +	return 0;
> +}
> +
> +static int __devexit restart_poweroff_remove(struct platform_device *pdev)
> +{
> +	if (pm_power_off == &restart_poweroff_do_poweroff)
> +		pm_power_off = NULL;
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id of_restart_poweroff_match[] = {
> +	{ .compatible = "restart-poweroff", },
> +	{},
> +};
> +
> +static struct platform_driver restart_poweroff_driver = {
> +	.probe = restart_poweroff_probe,
> +	.remove = __devexit_p(restart_poweroff_remove),
> +	.driver = {
> +		   .name = "poweroff-restart",
> +		   .owner = THIS_MODULE,
> +		   .of_match_table = of_restart_poweroff_match,
> +		   },
> +};
> +
> +module_platform_driver(restart_poweroff_driver);
> +
> +MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
> +MODULE_DESCRIPTION("restart poweroff driver");
> +MODULE_LICENSE("GPLv2");
> +MODULE_ALIAS("platform:poweroff-restart");


Tested-by: Michael Walle <michael@walle.cc>
Anton Vorontsov Jan. 6, 2013, 10:04 p.m. UTC | #2
On Fri, Dec 28, 2012 at 07:59:37PM +0100, Michael Walle wrote:
> Am Freitag 28 Dezember 2012, 13:25:11 schrieb Andrew Lunn:
> > Some devices, Buffalo Linkstation LS-XHL and LS-CHLv2 for example,
> > power-off by restarting to letting u-boot hold the SoC until the user
> > presses a key. Add a generic driver to implement this. It binds a
> > function to pm_power_off, which calls arm_pm_restart.
> > 
> > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
[...]
> Tested-by: Michael Walle <michael@walle.cc>

Applied (with a small cosmetic cleanups), thanks a lot!

Note that I can also take the ARM patches together with the drivers (and
it would make sense to keep things bisectable). Should I?

Thanks,
Anton
Andrew Lunn Jan. 7, 2013, 6:42 a.m. UTC | #3
On Sun, Jan 06, 2013 at 02:04:27PM -0800, Anton Vorontsov wrote:
> On Fri, Dec 28, 2012 at 07:59:37PM +0100, Michael Walle wrote:
> > Am Freitag 28 Dezember 2012, 13:25:11 schrieb Andrew Lunn:
> > > Some devices, Buffalo Linkstation LS-XHL and LS-CHLv2 for example,
> > > power-off by restarting to letting u-boot hold the SoC until the user
> > > presses a key. Add a generic driver to implement this. It binds a
> > > function to pm_power_off, which calls arm_pm_restart.
> > > 
> > > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> [...]
> > Tested-by: Michael Walle <michael@walle.cc>
> 
> Applied (with a small cosmetic cleanups), thanks a lot!
> 
> Note that I can also take the ARM patches together with the drivers (and
> it would make sense to keep things bisectable). Should I?

Hi Anton

Do you have a stable branch containing these patches? There are likely
to be some remove/remove conflicts with the ARM patches, which we can
avoid if you have a stable branch we can merge.

      Thanks
	Andrew
Anton Vorontsov Jan. 7, 2013, 7 a.m. UTC | #4
On Mon, Jan 07, 2013 at 07:42:02AM +0100, Andrew Lunn wrote:
> On Sun, Jan 06, 2013 at 02:04:27PM -0800, Anton Vorontsov wrote:
> > On Fri, Dec 28, 2012 at 07:59:37PM +0100, Michael Walle wrote:
> > > Am Freitag 28 Dezember 2012, 13:25:11 schrieb Andrew Lunn:
> > > > Some devices, Buffalo Linkstation LS-XHL and LS-CHLv2 for example,
> > > > power-off by restarting to letting u-boot hold the SoC until the user
> > > > presses a key. Add a generic driver to implement this. It binds a
> > > > function to pm_power_off, which calls arm_pm_restart.
> > > > 
> > > > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > [...]
> > > Tested-by: Michael Walle <michael@walle.cc>
> > 
> > Applied (with a small cosmetic cleanups), thanks a lot!
> > 
> > Note that I can also take the ARM patches together with the drivers (and
> > it would make sense to keep things bisectable). Should I?
> 
> Hi Anton
> 
> Do you have a stable branch containing these patches?

Stable as in 'I don't rebase it'? Yes, I tend to not rebase the battery
tree. It is here:

	git://git.infradead.org/battery-2.6.git master

You can find the applied patches there.

Thanks,
Anton
Jason Cooper Jan. 7, 2013, 11:27 a.m. UTC | #5
On Sun, Jan 06, 2013 at 02:04:27PM -0800, Anton Vorontsov wrote:
> On Fri, Dec 28, 2012 at 07:59:37PM +0100, Michael Walle wrote:
> > Am Freitag 28 Dezember 2012, 13:25:11 schrieb Andrew Lunn:
> > > Some devices, Buffalo Linkstation LS-XHL and LS-CHLv2 for example,
> > > power-off by restarting to letting u-boot hold the SoC until the user
> > > presses a key. Add a generic driver to implement this. It binds a
> > > function to pm_power_off, which calls arm_pm_restart.
> > > 
> > > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> [...]
> > Tested-by: Michael Walle <michael@walle.cc>
> 
> Applied (with a small cosmetic cleanups), thanks a lot!
> 
> Note that I can also take the ARM patches together with the drivers (and
> it would make sense to keep things bisectable). Should I?

Please take patches 1 and 3 of this series (which it looks like you
have).  I'll take 2 and 4 and list your stable tree as a dependency.

thx,

Jason.
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/power_supply/restart-poweroff.txt b/Documentation/devicetree/bindings/power_supply/restart-poweroff.txt
new file mode 100644
index 0000000..e4f1660
--- /dev/null
+++ b/Documentation/devicetree/bindings/power_supply/restart-poweroff.txt
@@ -0,0 +1,9 @@ 
+* Restart Power Off
+
+Buffalo Linkstation LS-XHL and LS-CHLv2, and other devices power off
+by restarting and letting u-boot keep hold of the machine until the
+user presses a button.
+
+Required Properties:
+- compatible: Should be "restart-poweroff"
+
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 6453aac..1ae65b8 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -22,3 +22,11 @@  config POWER_RESET_QNAP
 	  commands to the microcontroller which controls the main power.
 
 	  Say Y if you have a QNAP NAS.
+
+config POWER_RESET_RESTART
+	bool "Restart power-off driver"
+	depends on ARM
+	help
+	  Some boards don't actually have the ability to power off.
+	  Instead they restart, and u-boot holds the SoC until the
+	  user presses a key. u-boot then boots into Linux.
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index c4d3b2d..0f317f5 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -1,2 +1,3 @@ 
 obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
 obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o
+obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o
\ No newline at end of file
diff --git a/drivers/power/reset/restart-poweroff.c b/drivers/power/reset/restart-poweroff.c
new file mode 100644
index 0000000..79b1a2e
--- /dev/null
+++ b/drivers/power/reset/restart-poweroff.c
@@ -0,0 +1,67 @@ 
+/*
+ * Power off by restarting and let u-boot keep hold of the machine
+ * until the user presses a button for example.
+ *
+ * Andrew Lunn <andrew@lunn.ch>
+ *
+ * Copyright (C) 2012 Andrew Lunn
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <asm/system_misc.h>
+#include <linux/of_platform.h>
+#include <linux/module.h>
+
+static void restart_poweroff_do_poweroff(void)
+{
+	arm_pm_restart('h', NULL);
+}
+
+static int __devinit restart_poweroff_probe(struct platform_device *pdev)
+{
+	/* If a pm_power_off function has already been added, leave it alone */
+	if (pm_power_off != NULL) {
+		dev_err(&pdev->dev,
+			"pm_power_off function already registered");
+		return -EBUSY;
+	}
+
+	pm_power_off = &restart_poweroff_do_poweroff;
+	return 0;
+}
+
+static int __devexit restart_poweroff_remove(struct platform_device *pdev)
+{
+	if (pm_power_off == &restart_poweroff_do_poweroff)
+		pm_power_off = NULL;
+
+	return 0;
+}
+
+static const struct of_device_id of_restart_poweroff_match[] = {
+	{ .compatible = "restart-poweroff", },
+	{},
+};
+
+static struct platform_driver restart_poweroff_driver = {
+	.probe = restart_poweroff_probe,
+	.remove = __devexit_p(restart_poweroff_remove),
+	.driver = {
+		   .name = "poweroff-restart",
+		   .owner = THIS_MODULE,
+		   .of_match_table = of_restart_poweroff_match,
+		   },
+};
+
+module_platform_driver(restart_poweroff_driver);
+
+MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
+MODULE_DESCRIPTION("restart poweroff driver");
+MODULE_LICENSE("GPLv2");
+MODULE_ALIAS("platform:poweroff-restart");