Skip to contentSkip to conversation

Add support for generic register mapped poweroff.

PATCH Superseded Moritz Fischer 3 participants 9 messages Mar 10, 2015 – Mar 12, 2015

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add support for generic register mapped poweroff.

This patchset adds support for generic register mapped poweroff via SYCON.

Earlier versions of this were specific to our product, however, as Sebastian suggested, it can be generalized into a generic driver.

If an entry in the MAINTAINERS file is required I can resend a corrected version.

Moritz Fischer (2):
power: reset: Add generic SYSCON register mapped poweroff.
dt: power: Add docs for generic SYSCON poweroff driver.

 .../bindings/power/reset/syscon-poweroff.txt       | 23 +++++
 drivers/power/reset/Kconfig                        |  7 ++
 drivers/power/reset/Makefile                       |  1 +
 drivers/power/reset/syscon-poweroff.c              | 97 ++++++++++++++++++++++
 4 files changed, 128 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/reset/syscon-poweroff.txt
 create mode 100644 drivers/power/reset/syscon-poweroff.c
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/2 power: reset: Add generic SYSCON register mapped poweroff.

Add a generic SYSCON register mapped poweroff mechanism.

---
 drivers/power/reset/Kconfig           |  7 +++
 drivers/power/reset/Makefile          |  1 +
 drivers/power/reset/syscon-poweroff.c | 97 +++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+)
drivers/power/reset/Kconfig +7 -0
index 27f6646..4bae079 100644
@@ -151,6 +151,13 @@ config POWER_RESET_SYSCON
 	help
 	  Reboot support for generic SYSCON mapped register reset.
 
+config POWER_RESET_SYSCON_POWEROFF
+	bool "Generic SYSCON regmap poweroff driver"
+	depends on OF
+	select MFD_SYSCON
+	help
+	  Poweroff support for generic SYSCON mapped register poweroff.
+
 config POWER_RESET_RMOBILE
 	tristate "Renesas R-Mobile reset driver"
 	depends on ARCH_RMOBILE || COMPILE_TEST
drivers/power/reset/Makefile +1 -0
index 11de15b..dbe06c3 100644
@@ -17,4 +17,5 @@ obj-$(CONFIG_POWER_RESET_VEXPRESS) += vexpress-poweroff.o
 obj-$(CONFIG_POWER_RESET_XGENE) += xgene-reboot.o
 obj-$(CONFIG_POWER_RESET_KEYSTONE) += keystone-reset.o
 obj-$(CONFIG_POWER_RESET_SYSCON) += syscon-reboot.o
+obj-$(CONFIG_POWER_RESET_SYSCON_POWEROFF) += syscon-poweroff.o
 obj-$(CONFIG_POWER_RESET_RMOBILE) += rmobile-reset.o
drivers/power/reset/syscon-poweroff.c new file +97 -0

97 lines not on this page · raw message

Signature · 6 lines
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw

PATCH 2/2 dt: power: Add docs for generic SYSCON poweroff driver.

In reply to Moritz Fischer

Add documentation for generic SYSCON poweroff driver.

---
 .../bindings/power/reset/syscon-poweroff.txt       | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
Documentation/devicetree/bindings/power/reset/syscon-poweroff.txt new file +23 -0
new file mode 100644
index 0000000..1422cee
@@ -0,0 +1,23 @@
+Generic SYSCON mapped register poweroff driver
+
+This is a generic poweroff driver using syscon to map the poweroff register.
+The poweroff is generally performed with a write to the poweroff register
+defined by the register map pointed by syscon reference plus the offset
+with the mask defined in the poweroff node.
+
+Required properties:
+- compatible: should contain "syscon-poweroff"
+- regmap: this is phandle to the register map node
+- offset: offset in the register map for the poweroff register (in bytes)
+- mask: the poweroff value written to the poweroff register (32 bit access)
+
+Default will be little endian mode, 32 bit access only.
+
+Examples:
+
+	reboot {
+	   compatible = "syscon-reboot";
+	   regmap = <&regmapnode>;
+	   offset = <0x0>;
+	   mask = <0x7a>;
+	};
Signature · 1 line
1.9.3
#8 lore raw

Re: [PATCH 2/2] dt: power: Add docs for generic SYSCON poweroff driver.

Quoted 21 lines · Moritz Fischer

Add documentation for generic SYSCON poweroff driver.

---
 .../bindings/power/reset/syscon-poweroff.txt       | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
Documentation/devicetree/bindings/power/reset/syscon-poweroff.txt new file +8 -0
new file mode 100644
index 0000000..1422cee
@@ -0,0 +1,23 @@
+Generic SYSCON mapped register poweroff driver
+
+This is a generic poweroff driver using syscon to map the poweroff register.
+The poweroff is generally performed with a write to the poweroff register
+defined by the register map pointed by syscon reference plus the offset
+with the mask defined in the poweroff node.
+
+Required properties:

Documentation/devicetree/bindings/power/reset/syscon-poweroff.txt line 18

Quoted 10 lines
Documentation/devicetree/bindings/power/reset/syscon-poweroff.txt new file +10 -0
+- compatible: should contain "syscon-poweroff"
+- regmap: this is phandle to the register map node
+- offset: offset in the register map for the poweroff register (in bytes)
+- mask: the poweroff value written to the poweroff register (32 bit access)
+
+Default will be little endian mode, 32 bit access only.
+
+Examples:
+
+       reboot {

Arghhh ...

Documentation/devicetree/bindings/power/reset/syscon-poweroff.txt line 19

Quoted 1 line
Documentation/devicetree/bindings/power/reset/syscon-poweroff.txt new file +1 -0
+          compatible = "syscon-reboot";

Arghhhh.....

Quoted 7 lines
Documentation/devicetree/bindings/power/reset/syscon-poweroff.txt new file +4 -1
+          regmap = <&regmapnode>;
+          offset = <0x0>;
+          mask = <0x7a>;
+       };
--

1.9.3

Will collect feedback and resubmit, sorry about that.

Moritz

#2 lore raw

Re: [PATCH 1/2] power: reset: Add generic SYSCON register mapped poweroff.

In reply to Moritz Fischer

Hi,

Quoted 1 line · Moritz Fischer

Add a generic SYSCON register mapped poweroff mechanism.

Driver looks mostly fine.

drivers/power/reset/syscon-poweroff.c line 83

Quoted 8 lines

[...]

drivers/power/reset/syscon-poweroff.c new file +7 -0
+#ifdef CONFIG_OF
+static const struct of_device_id syscon_poweroff_of_match[] = {
+	{ .compatible = "syscon-poweroff" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, syscon_poweroff_of_match);
+#endif

You can remove the #ifdef, since the driver depends on OF.

drivers/power/reset/syscon-poweroff.c line 86

Quoted 2 lines
drivers/power/reset/syscon-poweroff.c new file +2 -0
+static struct platform_driver syscon_poweroff_driver = {
+	.probe = syscon_poweroff_probe,

You should set pm_power_off = NULL in .remove

drivers/power/reset/syscon-poweroff.c line 89

Quoted 3 lines
drivers/power/reset/syscon-poweroff.c new file +3 -0
+	.driver = {
+		.name = "syscon-poweroff",
+		.of_match_table = syscon_poweroff_of_match,

This would fail for !CONFIG_OF. If the driver has optional OF support you should use of_match_ptr(syscon_poweroff_of_match), which is a preprocessor macro returning NULL for !CONFIG_OF.

Quoted 11 lines
drivers/power/reset/syscon-poweroff.c new file +8 -0
+	},
+};
+module_platform_driver(syscon_poweroff_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Moritz Fischer <[email protected]>");
+MODULE_DESCRIPTION("Generic SYSCON poweroff driver");
+MODULE_ALIAS("platform:syscon-poweroff");
Signature · 1 line
1.9.3
#3 lore raw

Re: [PATCH 1/2] power: reset: Add generic SYSCON register mapped poweroff.

In reply to Moritz Fischer

drivers/power/reset/Kconfig config POWER_RESET_SYSCON · line 155

Quoted 5 lines · Moritz Fischer
drivers/power/reset/Kconfig +2 -0
 
+config POWER_RESET_SYSCON_POWEROFF
+	bool "Generic SYSCON regmap poweroff driver"

This adds a bool symbol.

drivers/power/reset/Makefile

Quoted 10 lines
drivers/power/reset/Kconfig +5 -0
+	depends on OF
+	select MFD_SYSCON
+	help
+	  Poweroff support for generic SYSCON mapped register poweroff.
+
drivers/power/reset/Makefile +1 -0
 
+obj-$(CONFIG_POWER_RESET_SYSCON_POWEROFF) += syscon-poweroff.o

So this objectfile can never be part of a module.

Quoted 11 lines
drivers/power/reset/syscon-poweroff.c new file +8 -0
@@ -0,0 +1,97 @@
+/*
+ * Generic Syscon Poweroff Driver
+ *
+ * Copyright (c) 2015, National Instruments Corp.
+ * Author: Moritz Fischer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as

drivers/power/reset/syscon-poweroff.c line 23

Quoted 10 lines
drivers/power/reset/syscon-poweroff.c new file +9 -0
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
+#include <linux/module.h>

Is that include needed?

Quoted 1 line

+MODULE_DEVICE_TABLE(of, syscon_poweroff_of_match);

This will be preprocessed away.

Quoted 1 line

+module_platform_driver(syscon_poweroff_driver);

I think the built-in equivalent of this would be adding a wrapper that only does

    platform_driver_register(&syscon_poweroff_driver);

and have that wrapper be marked with device_initcall(). Apparently there's no macro that does all that in one line.

Quoted 1 line

+MODULE_LICENSE("GPL v2");

You probably meant

    MODULE_LICENSE("GPL");

drivers/power/reset/syscon-poweroff.c line 97

Quoted 3 lines
drivers/power/reset/syscon-poweroff.c new file +3 -0
+MODULE_AUTHOR("Moritz Fischer <[email protected]>");
+MODULE_DESCRIPTION("Generic SYSCON poweroff driver");
+MODULE_ALIAS("platform:syscon-poweroff");

But these four macros will all be effectively preprocessed away, anyhow.

Paul Bolle

#4 lore raw

Re: [PATCH 1/2] power: reset: Add generic SYSCON register mapped poweroff.

Paul,

thanks for your feedback. While developing this I looked at other drivers in the tree and many of your comments would apply to them, too?

On Wed, Mar 11, 2015 at 2:31 AM, Paul Bolle <pebolle@tiscali

Quoted 4 lines

drivers/power/reset/Kconfig config POWER_RESET_SYSCON · line 155

Quoted 2 lines
drivers/power/reset/Kconfig +2 -0
+config POWER_RESET_SYSCON_POWEROFF
+     bool "Generic SYSCON regmap poweroff driver"

This adds a bool symbol.

Is that an issue or is it just to substantiate the rest of your comments below?

Quoted 3 lines
Quoted 1 line

+obj-$(CONFIG_POWER_RESET_SYSCON_POWEROFF) += syscon-poweroff.o

So this objectfile can never be part of a module.

Same comment would apply for power/reset/qnap-poweroff.c, right?

Quoted 3 lines
Quoted 1 line

+#include <linux/module.h>

Is that include needed?

Wouldn't that be needed if MODULE_DEVICE_TABLE etc, is used?

Quoted 3 lines
Quoted 1 line

+MODULE_DEVICE_TABLE(of, syscon_poweroff_of_match);

This will be preprocessed away.

In my experiments it didn't work without this, are you sure it's not needed?

Quoted 6 lines
Quoted 2 lines

+module_platform_driver(syscon_poweroff_driver);

I think the built-in equivalent of this would be adding a wrapper that only does

    platform_driver_register(&syscon_poweroff_driver);

I couldn't find other examples in the tree doing this. Any pointers?

Quoted 4 lines
Quoted 1 line

+MODULE_LICENSE("GPL v2");

You probably meant

    MODULE_LICENSE("GPL");

Sorry about that. Will fix.

Quoted 6 lines

drivers/power/reset/syscon-poweroff.c line 97

Quoted 4 lines
drivers/power/reset/syscon-poweroff.c new file +3 -0
+MODULE_AUTHOR("Moritz Fischer <[email protected]>");
+MODULE_DESCRIPTION("Generic SYSCON poweroff driver");
+MODULE_ALIAS("platform:syscon-poweroff");

But these four macros will all be effectively preprocessed away, anyhow.

I'll remove them.

Thanks,

Moritz

#5 lore raw

Re: [PATCH 1/2] power: reset: Add generic SYSCON register mapped poweroff.

Moritz,

Quoted 2 lines · Moritz Fischer

thanks for your feedback. While developing this I looked at other drivers in the tree and many of your comments would apply to them, too?

Could be. I didn't check. It's basically stuff that get's silently handled by the preprocessor. So I wouldn't be surprised if a lot of drivers do similar things.

Quoted 8 lines

On Wed, Mar 11, 2015 at 2:31 AM, Paul Bolle <pebolle@tiscali

Quoted 4 lines

drivers/power/reset/Kconfig config POWER_RESET_SYSCON · line 155

Quoted 2 lines
drivers/power/reset/Kconfig +2 -0
+config POWER_RESET_SYSCON_POWEROFF
+     bool "Generic SYSCON regmap poweroff driver"

This adds a bool symbol.

Is that an issue or is it just to substantiate the rest of your comments below?

It's just an observation.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+obj-$(CONFIG_POWER_RESET_SYSCON_POWEROFF) += syscon-poweroff.o

So this objectfile can never be part of a module.

Same comment would apply for power/reset/qnap-poweroff.c, right?

That could be. I didn't check it while looking at this patch.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+#include <linux/module.h>

Is that include needed?

Wouldn't that be needed if MODULE_DEVICE_TABLE etc, is used?

Perhaps, but I don't think those macros are used.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+MODULE_DEVICE_TABLE(of, syscon_poweroff_of_match);

This will be preprocessed away.

In my experiments it didn't work without this, are you sure it's not needed?

MODULE_DEVICE_TABLE() is defined only in include/linux/module.h. The few related lines read (in next-20150311):

    #ifdef MODULE
    /* Creates an alias so file2alias.c can find device table. */
    #define MODULE_DEVICE_TABLE(type, name)					\
    extern const typeof(name) __mod_##type##__##name##_device_table		\
      __attribute__ ((unused, alias(__stringify(name))))
    #else  /* !MODULE */
    #define MODULE_DEVICE_TABLE(type, name)
    #endif

So I think MODULE_DEVICE_TABLE() is always preprocessed away for boolean code. Did I get that right?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

+module_platform_driver(syscon_poweroff_driver);

I think the built-in equivalent of this would be adding a wrapper that only does

    platform_driver_register(&syscon_poweroff_driver);

I couldn't find other examples in the tree doing this. Any pointers?

Please note "think". But see drivers/cpufreq/dbx500-cpufreq.c:

    static int __init dbx500_cpufreq_register(void)
    {
            return platform_driver_register(&dbx500_cpufreq_plat_driver);
    }
    device_initcall(dbx500_cpufreq_register);

or drivers/gpio/gpio-vf610.c:

    static int __init gpio_vf610_init(void)
    {
            return platform_driver_register(&vf610_gpio_driver);
    }
    device_initcall(gpio_vf610_init);

(There are probably more.) Please note that both files use MODULE_* macros but can actually only be built-in.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+MODULE_LICENSE("GPL v2");

You probably meant

    MODULE_LICENSE("GPL");

Sorry about that. Will fix.

That's a very easy mistake to make anyway. There's currently a thread were (another) Dmitry and I discuss the merits of differentiating between "GPL" and "GPL v2" in MODULE_LICENSE().

Quoted 7 lines
Quoted 5 lines

drivers/power/reset/syscon-poweroff.c line 97

Quoted 3 lines
drivers/power/reset/syscon-poweroff.c new file +3 -0
+MODULE_AUTHOR("Moritz Fischer <[email protected]>");
+MODULE_DESCRIPTION("Generic SYSCON poweroff driver");
+MODULE_ALIAS("platform:syscon-poweroff");

But these four macros will all be effectively preprocessed away, anyhow.

I'll remove them.

Thanks,

Paul Bolle

#6 lore raw

Re: [PATCH 1/2] power: reset: Add generic SYSCON register mapped poweroff.

Paul,

Quoted 11 lines · Paul Bolle

MODULE_DEVICE_TABLE() is defined only in include/linux/module.h. The few related lines read (in next-20150311):

    #ifdef MODULE
    /* Creates an alias so file2alias.c can find device table. */
    #define MODULE_DEVICE_TABLE(type, name)                                     \
    extern const typeof(name) __mod_##type##__##name##_device_table             \
      __attribute__ ((unused, alias(__stringify(name))))
    #else  /* !MODULE */
    #define MODULE_DEVICE_TABLE(type, name)
    #endif
Quoted 2 lines

So I think MODULE_DEVICE_TABLE() is always preprocessed away for boolean code. Did I get that right?

Yeah, looking at that convinced me :) I have it already removed in v2.

Quoted 16 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

+module_platform_driver(syscon_poweroff_driver);

I think the built-in equivalent of this would be adding a wrapper that only does

    platform_driver_register(&syscon_poweroff_driver);

I couldn't find other examples in the tree doing this. Any pointers?

Please note "think". But see drivers/cpufreq/dbx500-cpufreq.c:

    static int __init dbx500_cpufreq_register(void)
    {
            return platform_driver_register(&dbx500_cpufreq_plat_driver);
    }
    device_initcall(dbx500_cpufreq_register);
Quoted 6 lines

or drivers/gpio/gpio-vf610.c:

    static int __init gpio_vf610_init(void)
    {
            return platform_driver_register(&vf610_gpio_driver);
    }
    device_initcall(gpio_vf610_init);

I included it into v3. Thanks.

Thanks again for your feedback,

Moritz