* [PATCH v3 0/2] power: reset: support for Atmel alternative Shutdown Controller
@ 2015-09-30 16:21 ` Nicolas Ferre
0 siblings, 0 replies; 14+ messages in thread
From: Nicolas Ferre @ 2015-09-30 16:21 UTC (permalink / raw)
To: linux-arm-kernel, sre, Alexandre Belloni, robh+dt
Cc: linux-kernel, Maxime Ripard, linux, mark.rutland, ijc+devicetree,
Jean-Christophe PLAGNIOL-VILLARD, Nicolas Ferre
This is a series to add driver for a new Atmel Shutdown Controller. This new IP
is extensible and some features will be added later (see the TODO section).
Its extensible nature led to write a new binding so that wake-up sources can be
described easily.
Changes in v3:
- get and use slow clock and specify its handler in binding
- add the slow clock handle as the IP uses it
- remove useless protection at the beginning of pm_power_off handler
- allow to compile it as a module
- add COMPILE_TEST directive in Kconfig
- update description in file header
Changes in v2:
- add MODULE_DEVICE_TABLE as advised by Sebastian Reichel
- review indentation and braces to correct errors pointed out by checkpatch
Nicolas Ferre (2):
ARM: at91/dt: shdwc binding: add new shutdown controller documentation
power: reset: at91-shdwc: add new shutdown controller driver
.../devicetree/bindings/arm/atmel-at91.txt | 54 ++++
drivers/power/reset/Kconfig | 8 +
drivers/power/reset/Makefile | 1 +
drivers/power/reset/at91-shdwc.c | 288 +++++++++++++++++++++
4 files changed, 351 insertions(+)
create mode 100644 drivers/power/reset/at91-shdwc.c
--
2.1.3
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 0/2] power: reset: support for Atmel alternative Shutdown Controller
@ 2015-09-30 16:21 ` Nicolas Ferre
0 siblings, 0 replies; 14+ messages in thread
From: Nicolas Ferre @ 2015-09-30 16:21 UTC (permalink / raw)
To: linux-arm-kernel
This is a series to add driver for a new Atmel Shutdown Controller. This new IP
is extensible and some features will be added later (see the TODO section).
Its extensible nature led to write a new binding so that wake-up sources can be
described easily.
Changes in v3:
- get and use slow clock and specify its handler in binding
- add the slow clock handle as the IP uses it
- remove useless protection at the beginning of pm_power_off handler
- allow to compile it as a module
- add COMPILE_TEST directive in Kconfig
- update description in file header
Changes in v2:
- add MODULE_DEVICE_TABLE as advised by Sebastian Reichel
- review indentation and braces to correct errors pointed out by checkpatch
Nicolas Ferre (2):
ARM: at91/dt: shdwc binding: add new shutdown controller documentation
power: reset: at91-shdwc: add new shutdown controller driver
.../devicetree/bindings/arm/atmel-at91.txt | 54 ++++
drivers/power/reset/Kconfig | 8 +
drivers/power/reset/Makefile | 1 +
drivers/power/reset/at91-shdwc.c | 288 +++++++++++++++++++++
4 files changed, 351 insertions(+)
create mode 100644 drivers/power/reset/at91-shdwc.c
--
2.1.3
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 1/2] ARM: at91/dt: shdwc binding: add new shutdown controller documentation
2015-09-30 16:21 ` Nicolas Ferre
@ 2015-09-30 16:22 ` Nicolas Ferre
-1 siblings, 0 replies; 14+ messages in thread
From: Nicolas Ferre @ 2015-09-30 16:22 UTC (permalink / raw)
To: linux-arm-kernel, sre, Alexandre Belloni, robh+dt
Cc: linux-kernel, Maxime Ripard, linux, mark.rutland, ijc+devicetree,
Jean-Christophe PLAGNIOL-VILLARD, Nicolas Ferre
The new shutdown controller compatible with sama5d2 has a new binding
documentation and properties.
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
Changes in v3:
- get and use slow clock and specify its handler in binding
Changes in v2: None
.../devicetree/bindings/arm/atmel-at91.txt | 54 ++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/Documentation/devicetree/bindings/arm/atmel-at91.txt b/Documentation/devicetree/bindings/arm/atmel-at91.txt
index 7fd64ec9ee1d..253e573f28c4 100644
--- a/Documentation/devicetree/bindings/arm/atmel-at91.txt
+++ b/Documentation/devicetree/bindings/arm/atmel-at91.txt
@@ -147,6 +147,60 @@ Example:
clocks = <&clk32k>;
};
+SHDWC Shutdown Controller (Alternative)
+
+1) shdwc node
+
+required properties:
+- compatible: should be "atmel,sama5d2-shdwc".
+- reg: should contain registers location and length
+- clocks: phandle to input clock.
+- #address-cells: should be one. The cell is the wake-up input index.
+- #size-cells: should be zero.
+
+optional properties:
+
+- atmel,wakeup-debouncer: minimum wake-up inputs debouncer period in
+ micro-seconds. It's usually a board-related property.
+- atmel,wakeup-rtc-timer: boolean to enable Real-Time Clock wake-up.
+
+The node contains child nodes for each wake-up input that the platform uses.
+
+2) input nodes
+
+Wake-up input nodes are usually described in the "board" part of the Device
+Tree. Note also that input 0 is linked to the wake-up pin and is frequently
+used.
+
+Required properties:
+- reg: should contain the wake-up input index [0 - 15].
+
+Optional properties:
+- atmel,wakeup-type: string, operation mode of the input described by the child
+ node. Supported values are: "high" or "low".
+
+Example:
+
+On the SoC side:
+ shdwc@f8048010 {
+ compatible = "atmel,sama5d2-shdwc";
+ reg = <0xf8048010 0x10>;
+ clocks = <&clk32k>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+ atmel,wakeup-rtc-timer;
+ };
+
+On the board side:
+ shdwc@f8048010 {
+ atmel,shdwc-debouncer = <976>;
+
+ input@0 {
+ reg = <0>;
+ atmel,wakeup-type = "low";
+ };
+ };
+
Special Function Registers (SFR)
Special Function Registers (SFR) manage specific aspects of the integrated
--
2.1.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 1/2] ARM: at91/dt: shdwc binding: add new shutdown controller documentation
@ 2015-09-30 16:22 ` Nicolas Ferre
0 siblings, 0 replies; 14+ messages in thread
From: Nicolas Ferre @ 2015-09-30 16:22 UTC (permalink / raw)
To: linux-arm-kernel
The new shutdown controller compatible with sama5d2 has a new binding
documentation and properties.
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
Changes in v3:
- get and use slow clock and specify its handler in binding
Changes in v2: None
.../devicetree/bindings/arm/atmel-at91.txt | 54 ++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/Documentation/devicetree/bindings/arm/atmel-at91.txt b/Documentation/devicetree/bindings/arm/atmel-at91.txt
index 7fd64ec9ee1d..253e573f28c4 100644
--- a/Documentation/devicetree/bindings/arm/atmel-at91.txt
+++ b/Documentation/devicetree/bindings/arm/atmel-at91.txt
@@ -147,6 +147,60 @@ Example:
clocks = <&clk32k>;
};
+SHDWC Shutdown Controller (Alternative)
+
+1) shdwc node
+
+required properties:
+- compatible: should be "atmel,sama5d2-shdwc".
+- reg: should contain registers location and length
+- clocks: phandle to input clock.
+- #address-cells: should be one. The cell is the wake-up input index.
+- #size-cells: should be zero.
+
+optional properties:
+
+- atmel,wakeup-debouncer: minimum wake-up inputs debouncer period in
+ micro-seconds. It's usually a board-related property.
+- atmel,wakeup-rtc-timer: boolean to enable Real-Time Clock wake-up.
+
+The node contains child nodes for each wake-up input that the platform uses.
+
+2) input nodes
+
+Wake-up input nodes are usually described in the "board" part of the Device
+Tree. Note also that input 0 is linked to the wake-up pin and is frequently
+used.
+
+Required properties:
+- reg: should contain the wake-up input index [0 - 15].
+
+Optional properties:
+- atmel,wakeup-type: string, operation mode of the input described by the child
+ node. Supported values are: "high" or "low".
+
+Example:
+
+On the SoC side:
+ shdwc at f8048010 {
+ compatible = "atmel,sama5d2-shdwc";
+ reg = <0xf8048010 0x10>;
+ clocks = <&clk32k>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+ atmel,wakeup-rtc-timer;
+ };
+
+On the board side:
+ shdwc at f8048010 {
+ atmel,shdwc-debouncer = <976>;
+
+ input at 0 {
+ reg = <0>;
+ atmel,wakeup-type = "low";
+ };
+ };
+
Special Function Registers (SFR)
Special Function Registers (SFR) manage specific aspects of the integrated
--
2.1.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 2/2] power: reset: at91-shdwc: add new shutdown controller driver
2015-09-30 16:21 ` Nicolas Ferre
@ 2015-09-30 16:22 ` Nicolas Ferre
-1 siblings, 0 replies; 14+ messages in thread
From: Nicolas Ferre @ 2015-09-30 16:22 UTC (permalink / raw)
To: linux-arm-kernel, sre, Alexandre Belloni, robh+dt
Cc: linux-kernel, Maxime Ripard, linux, mark.rutland, ijc+devicetree,
Jean-Christophe PLAGNIOL-VILLARD, Nicolas Ferre
Sama5d2 SoC has a completely new shutdown controller with new features and
register layout. It thus makes sense to add a new driver for this new
peripheral.
This driver is Device Tree only and handles events from the wake-up pin and
the RTC.
As the register layout may change in the future, so some values are encoded
in a configuration structure.
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
Changes in v3:
- add the slow clock handle as the IP uses it
- remove useless protection at the beginning of pm_power_off handler
- allow to compile it as a module
- add COMPILE_TEST directive in Kconfig
- update description in file header
Changes in v2:
- add MODULE_DEVICE_TABLE as advised by Sebastian Reichel
- review indentation and braces to correct errors pointed out by checkpatch
drivers/power/reset/Kconfig | 8 ++
drivers/power/reset/Makefile | 1 +
drivers/power/reset/at91-shdwc.c | 288 +++++++++++++++++++++++++++++++++++++++
3 files changed, 297 insertions(+)
create mode 100644 drivers/power/reset/at91-shdwc.c
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 1131cf75acc6..c989ffae7143 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -30,6 +30,14 @@ config POWER_RESET_AT91_RESET
This driver supports restart for Atmel AT91SAM9 and SAMA5
SoCs
+config POWER_RESET_AT91_SHDWC
+ tristate "Atmel AT91 shutdown controller driver"
+ depends on ARCH_AT91 || COMPILE_TEST
+ default SOC_SAMA5
+ help
+ This driver supports the alternate shutdown controller for some Atmel
+ SAMA5 SoCs. It is present for example on SAMA5D2 SoC.
+
config POWER_RESET_AXXIA
bool "LSI Axxia reset driver"
depends on ARCH_AXXIA
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 096fa67047f6..6b9020ed3fb7 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -1,6 +1,7 @@
obj-$(CONFIG_POWER_RESET_AS3722) += as3722-poweroff.o
obj-$(CONFIG_POWER_RESET_AT91_POWEROFF) += at91-poweroff.o
obj-$(CONFIG_POWER_RESET_AT91_RESET) += at91-reset.o
+obj-$(CONFIG_POWER_RESET_AT91_SHDWC) += at91-shdwc.o
obj-$(CONFIG_POWER_RESET_AXXIA) += axxia-reset.o
obj-$(CONFIG_POWER_RESET_BRCMSTB) += brcmstb-reboot.o
obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
diff --git a/drivers/power/reset/at91-shdwc.c b/drivers/power/reset/at91-shdwc.c
new file mode 100644
index 000000000000..9163ebde9f14
--- /dev/null
+++ b/drivers/power/reset/at91-shdwc.c
@@ -0,0 +1,288 @@
+/*
+ * Atmel alternative Shutdown Controller (SHDWC) driver.
+ * Found on some SoCs as the sama5d2 for instance.
+ *
+ * Copyright (C) 2015 Atmel Corporation,
+ * Nicolas Ferre <nicolas.ferre@atmel.com>
+ *
+ * Evolved from driver at91-poweroff.c.
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ *
+ * TODO:
+ * - addition to status of other wake-up inputs [1 - 15]
+ * - Analog Comparator wake-up alarm
+ * - Serial RX wake-up alarm
+ * - low power debouncer
+ */
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/printk.h>
+
+#define SLOW_CLOCK_FREQ 32768
+
+#define AT91_SHDW_CR 0x00 /* Shut Down Control Register */
+#define AT91_SHDW_SHDW BIT(0) /* Shut Down command */
+#define AT91_SHDW_KEY (0xa5 << 24) /* KEY Password */
+
+#define AT91_SHDW_MR 0x04 /* Shut Down Mode Register */
+#define AT91_SHDW_WKUPDBC_SHIFT 24
+#define AT91_SHDW_WKUPDBC_MASK GENMASK(31, 16)
+#define AT91_SHDW_WKUPDBC(x) (((x) << AT91_SHDW_WKUPDBC_SHIFT) \
+ & AT91_SHDW_WKUPDBC_MASK)
+
+#define AT91_SHDW_SR 0x08 /* Shut Down Status Register */
+#define AT91_SHDW_WKUPIS_SHIFT 16
+#define AT91_SHDW_WKUPIS_MASK GENMASK(31, 16)
+#define AT91_SHDW_WKUPIS(x) ((1 << (x)) << AT91_SHDW_WKUPIS_SHIFT \
+ & AT91_SHDW_WKUPIS_MASK)
+
+#define AT91_SHDW_WUIR 0x0c /* Shutdown Wake-up Inputs Register */
+#define AT91_SHDW_WKUPEN_MASK GENMASK(15, 0)
+#define AT91_SHDW_WKUPEN(x) ((1 << (x)) & AT91_SHDW_WKUPEN_MASK)
+#define AT91_SHDW_WKUPT_SHIFT 16
+#define AT91_SHDW_WKUPT_MASK GENMASK(31, 16)
+#define AT91_SHDW_WKUPT(x) ((1 << (x)) << AT91_SHDW_WKUPT_SHIFT \
+ & AT91_SHDW_WKUPT_MASK)
+
+#define SHDW_WK_PIN(reg, cfg) ((reg) & AT91_SHDW_WKUPIS((cfg)->wkup_pin_input))
+#define SHDW_RTCWK(reg, cfg) (((reg) >> ((cfg)->sr_rtcwk_shift)) & 0x1)
+#define SHDW_RTCWKEN(cfg) (1 << ((cfg)->mr_rtcwk_shift))
+
+#define DBC_PERIOD_US(x) DIV_ROUND_UP_ULL((1000000 * (x)), \
+ SLOW_CLOCK_FREQ)
+
+struct shdwc_config {
+ u8 wkup_pin_input;
+ u8 mr_rtcwk_shift;
+ u8 sr_rtcwk_shift;
+};
+
+struct shdwc {
+ struct shdwc_config *cfg;
+ void __iomem *at91_shdwc_base;
+};
+
+/*
+ * Hold configuration here, cannot be more than one instance of the driver
+ * since pm_power_off itself is global.
+ */
+static struct shdwc *at91_shdwc;
+static struct clk *sclk;
+
+static const unsigned long long sdwc_dbc_period[] = {
+ 0, 3, 32, 512, 4096, 32768,
+};
+
+static void __init at91_wakeup_status(struct platform_device *pdev)
+{
+ struct shdwc *shdw = platform_get_drvdata(pdev);
+ u32 reg;
+ char *reason = "unknown";
+
+ reg = readl(shdw->at91_shdwc_base + AT91_SHDW_SR);
+
+ dev_dbg(&pdev->dev, "%s: status = %#x\n", __func__, reg);
+
+ /* Simple power-on, just bail out */
+ if (!reg)
+ return;
+
+ if (SHDW_WK_PIN(reg, shdw->cfg))
+ reason = "WKUP pin";
+ else if (SHDW_RTCWK(reg, shdw->cfg))
+ reason = "RTC";
+
+ pr_info("AT91: Wake-Up source: %s\n", reason);
+}
+
+static void at91_poweroff(void)
+{
+ writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
+ at91_shdwc->at91_shdwc_base + AT91_SHDW_CR);
+}
+
+static u32 at91_shdwc_debouncer_value(struct platform_device *pdev,
+ u32 in_period_us)
+{
+ int i;
+ int max_idx = ARRAY_SIZE(sdwc_dbc_period) - 1;
+ unsigned long long period_us;
+ unsigned long long max_period_us = DBC_PERIOD_US(sdwc_dbc_period[max_idx]);
+
+ if (in_period_us > max_period_us) {
+ dev_warn(&pdev->dev,
+ "debouncer period %u too big, reduced to %llu us\n",
+ in_period_us, max_period_us);
+ return max_idx;
+ }
+
+ for (i = max_idx - 1; i > 0; i--) {
+ period_us = DBC_PERIOD_US(sdwc_dbc_period[i]);
+ dev_dbg(&pdev->dev, "%s: ref[%d] = %llu\n",
+ __func__, i, period_us);
+ if (in_period_us > period_us)
+ break;
+ }
+
+ return i + 1;
+}
+
+static u32 at91_shdwc_get_wakeup_input(struct platform_device *pdev,
+ struct device_node *np)
+{
+ struct device_node *cnp;
+ const char *pm;
+ u32 wk_input_mask;
+ u32 wuir = 0;
+ u32 wk_input;
+
+ for_each_child_of_node(np, cnp) {
+ if (of_property_read_u32(cnp, "reg", &wk_input)) {
+ dev_warn(&pdev->dev, "reg property is missing for %s\n",
+ cnp->full_name);
+ continue;
+ }
+
+ wk_input_mask = 1 << wk_input;
+ if (!(wk_input_mask & AT91_SHDW_WKUPEN_MASK)) {
+ dev_warn(&pdev->dev,
+ "wake-up input %d out of bounds ignore\n",
+ wk_input);
+ continue;
+ }
+ wuir |= wk_input_mask;
+
+ if (!of_property_read_string(cnp, "atmel,wakeup-type", &pm)) {
+ if (!strcasecmp(pm, "high"))
+ /*
+ * only add a type if "high" is specified. Low
+ * is the default.
+ */
+ wuir |= AT91_SHDW_WKUPT(wk_input);
+ }
+ dev_dbg(&pdev->dev, "%s: (child %d) wuir = %#x\n",
+ __func__, wk_input, wuir);
+ }
+
+ return wuir;
+}
+
+static void at91_shdwc_dt_configure(struct platform_device *pdev)
+{
+ struct shdwc *shdw = platform_get_drvdata(pdev);
+ struct device_node *np = pdev->dev.of_node;
+ u32 mode = 0, tmp, input;
+
+ if (!np) {
+ dev_err(&pdev->dev, "device node not found\n");
+ return;
+ }
+
+ if (!of_property_read_u32(np, "atmel,shdwc-debouncer", &tmp))
+ mode |= AT91_SHDW_WKUPDBC(at91_shdwc_debouncer_value(pdev, tmp));
+
+ if (of_property_read_bool(np, "atmel,wakeup-rtc-timer"))
+ mode |= SHDW_RTCWKEN(shdw->cfg);
+
+ dev_dbg(&pdev->dev, "%s: mode = %#x\n", __func__, mode);
+ writel(mode, shdw->at91_shdwc_base + AT91_SHDW_MR);
+
+ input = at91_shdwc_get_wakeup_input(pdev, np);
+ writel(input, shdw->at91_shdwc_base + AT91_SHDW_WUIR);
+}
+
+static const struct shdwc_config sama5d2_shdwc_config = {
+ .wkup_pin_input = 0,
+ .mr_rtcwk_shift = 17,
+ .sr_rtcwk_shift = 5,
+};
+
+static const struct of_device_id at91_shdwc_of_match[] = {
+ {
+ .compatible = "atmel,sama5d2-shdwc",
+ .data = &sama5d2_shdwc_config,
+ }, {
+ /*sentinel*/
+ }
+};
+MODULE_DEVICE_TABLE(of, at91_shdwc_of_match);
+
+static int __init at91_shdwc_probe(struct platform_device *pdev)
+{
+ struct resource *res;
+ const struct of_device_id *match;
+ int ret;
+
+ if (!pdev->dev.of_node)
+ return -ENODEV;
+
+ at91_shdwc = devm_kzalloc(&pdev->dev, sizeof(*at91_shdwc), GFP_KERNEL);
+ if (!at91_shdwc)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, at91_shdwc);
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ at91_shdwc->at91_shdwc_base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(at91_shdwc->at91_shdwc_base)) {
+ dev_err(&pdev->dev, "Could not map reset controller address\n");
+ return PTR_ERR(at91_shdwc->at91_shdwc_base);
+ }
+
+ match = of_match_node(at91_shdwc_of_match, pdev->dev.of_node);
+ at91_shdwc->cfg = (struct shdwc_config *)(match->data);
+
+ sclk = devm_clk_get(&pdev->dev, NULL);
+ if (IS_ERR(sclk))
+ return PTR_ERR(sclk);
+
+ ret = clk_prepare_enable(sclk);
+ if (ret) {
+ dev_err(&pdev->dev, "Could not enable slow clock\n");
+ return ret;
+ }
+
+ at91_wakeup_status(pdev);
+
+ at91_shdwc_dt_configure(pdev);
+
+ pm_power_off = at91_poweroff;
+
+ return 0;
+}
+
+static int __exit at91_shdwc_remove(struct platform_device *pdev)
+{
+ struct shdwc *shdw = platform_get_drvdata(pdev);
+
+ if (pm_power_off == at91_poweroff)
+ pm_power_off = NULL;
+
+ /* Reset values to disable wake-up features */
+ writel(0, shdw->at91_shdwc_base + AT91_SHDW_MR);
+ writel(0, shdw->at91_shdwc_base + AT91_SHDW_WUIR);
+
+ clk_disable_unprepare(sclk);
+
+ return 0;
+}
+
+static struct platform_driver at91_shdwc_driver = {
+ .remove = __exit_p(at91_shdwc_remove),
+ .driver = {
+ .name = "at91-shdwc",
+ .of_match_table = at91_shdwc_of_match,
+ },
+};
+module_platform_driver_probe(at91_shdwc_driver, at91_shdwc_probe);
+
+MODULE_AUTHOR("Nicolas Ferre <nicolas.ferre@atmel.com>");
+MODULE_DESCRIPTION("Atmel shutdown controller driver");
+MODULE_LICENSE("GPL v2");
--
2.1.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 2/2] power: reset: at91-shdwc: add new shutdown controller driver
@ 2015-09-30 16:22 ` Nicolas Ferre
0 siblings, 0 replies; 14+ messages in thread
From: Nicolas Ferre @ 2015-09-30 16:22 UTC (permalink / raw)
To: linux-arm-kernel
Sama5d2 SoC has a completely new shutdown controller with new features and
register layout. It thus makes sense to add a new driver for this new
peripheral.
This driver is Device Tree only and handles events from the wake-up pin and
the RTC.
As the register layout may change in the future, so some values are encoded
in a configuration structure.
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
Changes in v3:
- add the slow clock handle as the IP uses it
- remove useless protection at the beginning of pm_power_off handler
- allow to compile it as a module
- add COMPILE_TEST directive in Kconfig
- update description in file header
Changes in v2:
- add MODULE_DEVICE_TABLE as advised by Sebastian Reichel
- review indentation and braces to correct errors pointed out by checkpatch
drivers/power/reset/Kconfig | 8 ++
drivers/power/reset/Makefile | 1 +
drivers/power/reset/at91-shdwc.c | 288 +++++++++++++++++++++++++++++++++++++++
3 files changed, 297 insertions(+)
create mode 100644 drivers/power/reset/at91-shdwc.c
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 1131cf75acc6..c989ffae7143 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -30,6 +30,14 @@ config POWER_RESET_AT91_RESET
This driver supports restart for Atmel AT91SAM9 and SAMA5
SoCs
+config POWER_RESET_AT91_SHDWC
+ tristate "Atmel AT91 shutdown controller driver"
+ depends on ARCH_AT91 || COMPILE_TEST
+ default SOC_SAMA5
+ help
+ This driver supports the alternate shutdown controller for some Atmel
+ SAMA5 SoCs. It is present for example on SAMA5D2 SoC.
+
config POWER_RESET_AXXIA
bool "LSI Axxia reset driver"
depends on ARCH_AXXIA
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 096fa67047f6..6b9020ed3fb7 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -1,6 +1,7 @@
obj-$(CONFIG_POWER_RESET_AS3722) += as3722-poweroff.o
obj-$(CONFIG_POWER_RESET_AT91_POWEROFF) += at91-poweroff.o
obj-$(CONFIG_POWER_RESET_AT91_RESET) += at91-reset.o
+obj-$(CONFIG_POWER_RESET_AT91_SHDWC) += at91-shdwc.o
obj-$(CONFIG_POWER_RESET_AXXIA) += axxia-reset.o
obj-$(CONFIG_POWER_RESET_BRCMSTB) += brcmstb-reboot.o
obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
diff --git a/drivers/power/reset/at91-shdwc.c b/drivers/power/reset/at91-shdwc.c
new file mode 100644
index 000000000000..9163ebde9f14
--- /dev/null
+++ b/drivers/power/reset/at91-shdwc.c
@@ -0,0 +1,288 @@
+/*
+ * Atmel alternative Shutdown Controller (SHDWC) driver.
+ * Found on some SoCs as the sama5d2 for instance.
+ *
+ * Copyright (C) 2015 Atmel Corporation,
+ * Nicolas Ferre <nicolas.ferre@atmel.com>
+ *
+ * Evolved from driver at91-poweroff.c.
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ *
+ * TODO:
+ * - addition to status of other wake-up inputs [1 - 15]
+ * - Analog Comparator wake-up alarm
+ * - Serial RX wake-up alarm
+ * - low power debouncer
+ */
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/printk.h>
+
+#define SLOW_CLOCK_FREQ 32768
+
+#define AT91_SHDW_CR 0x00 /* Shut Down Control Register */
+#define AT91_SHDW_SHDW BIT(0) /* Shut Down command */
+#define AT91_SHDW_KEY (0xa5 << 24) /* KEY Password */
+
+#define AT91_SHDW_MR 0x04 /* Shut Down Mode Register */
+#define AT91_SHDW_WKUPDBC_SHIFT 24
+#define AT91_SHDW_WKUPDBC_MASK GENMASK(31, 16)
+#define AT91_SHDW_WKUPDBC(x) (((x) << AT91_SHDW_WKUPDBC_SHIFT) \
+ & AT91_SHDW_WKUPDBC_MASK)
+
+#define AT91_SHDW_SR 0x08 /* Shut Down Status Register */
+#define AT91_SHDW_WKUPIS_SHIFT 16
+#define AT91_SHDW_WKUPIS_MASK GENMASK(31, 16)
+#define AT91_SHDW_WKUPIS(x) ((1 << (x)) << AT91_SHDW_WKUPIS_SHIFT \
+ & AT91_SHDW_WKUPIS_MASK)
+
+#define AT91_SHDW_WUIR 0x0c /* Shutdown Wake-up Inputs Register */
+#define AT91_SHDW_WKUPEN_MASK GENMASK(15, 0)
+#define AT91_SHDW_WKUPEN(x) ((1 << (x)) & AT91_SHDW_WKUPEN_MASK)
+#define AT91_SHDW_WKUPT_SHIFT 16
+#define AT91_SHDW_WKUPT_MASK GENMASK(31, 16)
+#define AT91_SHDW_WKUPT(x) ((1 << (x)) << AT91_SHDW_WKUPT_SHIFT \
+ & AT91_SHDW_WKUPT_MASK)
+
+#define SHDW_WK_PIN(reg, cfg) ((reg) & AT91_SHDW_WKUPIS((cfg)->wkup_pin_input))
+#define SHDW_RTCWK(reg, cfg) (((reg) >> ((cfg)->sr_rtcwk_shift)) & 0x1)
+#define SHDW_RTCWKEN(cfg) (1 << ((cfg)->mr_rtcwk_shift))
+
+#define DBC_PERIOD_US(x) DIV_ROUND_UP_ULL((1000000 * (x)), \
+ SLOW_CLOCK_FREQ)
+
+struct shdwc_config {
+ u8 wkup_pin_input;
+ u8 mr_rtcwk_shift;
+ u8 sr_rtcwk_shift;
+};
+
+struct shdwc {
+ struct shdwc_config *cfg;
+ void __iomem *at91_shdwc_base;
+};
+
+/*
+ * Hold configuration here, cannot be more than one instance of the driver
+ * since pm_power_off itself is global.
+ */
+static struct shdwc *at91_shdwc;
+static struct clk *sclk;
+
+static const unsigned long long sdwc_dbc_period[] = {
+ 0, 3, 32, 512, 4096, 32768,
+};
+
+static void __init at91_wakeup_status(struct platform_device *pdev)
+{
+ struct shdwc *shdw = platform_get_drvdata(pdev);
+ u32 reg;
+ char *reason = "unknown";
+
+ reg = readl(shdw->at91_shdwc_base + AT91_SHDW_SR);
+
+ dev_dbg(&pdev->dev, "%s: status = %#x\n", __func__, reg);
+
+ /* Simple power-on, just bail out */
+ if (!reg)
+ return;
+
+ if (SHDW_WK_PIN(reg, shdw->cfg))
+ reason = "WKUP pin";
+ else if (SHDW_RTCWK(reg, shdw->cfg))
+ reason = "RTC";
+
+ pr_info("AT91: Wake-Up source: %s\n", reason);
+}
+
+static void at91_poweroff(void)
+{
+ writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
+ at91_shdwc->at91_shdwc_base + AT91_SHDW_CR);
+}
+
+static u32 at91_shdwc_debouncer_value(struct platform_device *pdev,
+ u32 in_period_us)
+{
+ int i;
+ int max_idx = ARRAY_SIZE(sdwc_dbc_period) - 1;
+ unsigned long long period_us;
+ unsigned long long max_period_us = DBC_PERIOD_US(sdwc_dbc_period[max_idx]);
+
+ if (in_period_us > max_period_us) {
+ dev_warn(&pdev->dev,
+ "debouncer period %u too big, reduced to %llu us\n",
+ in_period_us, max_period_us);
+ return max_idx;
+ }
+
+ for (i = max_idx - 1; i > 0; i--) {
+ period_us = DBC_PERIOD_US(sdwc_dbc_period[i]);
+ dev_dbg(&pdev->dev, "%s: ref[%d] = %llu\n",
+ __func__, i, period_us);
+ if (in_period_us > period_us)
+ break;
+ }
+
+ return i + 1;
+}
+
+static u32 at91_shdwc_get_wakeup_input(struct platform_device *pdev,
+ struct device_node *np)
+{
+ struct device_node *cnp;
+ const char *pm;
+ u32 wk_input_mask;
+ u32 wuir = 0;
+ u32 wk_input;
+
+ for_each_child_of_node(np, cnp) {
+ if (of_property_read_u32(cnp, "reg", &wk_input)) {
+ dev_warn(&pdev->dev, "reg property is missing for %s\n",
+ cnp->full_name);
+ continue;
+ }
+
+ wk_input_mask = 1 << wk_input;
+ if (!(wk_input_mask & AT91_SHDW_WKUPEN_MASK)) {
+ dev_warn(&pdev->dev,
+ "wake-up input %d out of bounds ignore\n",
+ wk_input);
+ continue;
+ }
+ wuir |= wk_input_mask;
+
+ if (!of_property_read_string(cnp, "atmel,wakeup-type", &pm)) {
+ if (!strcasecmp(pm, "high"))
+ /*
+ * only add a type if "high" is specified. Low
+ * is the default.
+ */
+ wuir |= AT91_SHDW_WKUPT(wk_input);
+ }
+ dev_dbg(&pdev->dev, "%s: (child %d) wuir = %#x\n",
+ __func__, wk_input, wuir);
+ }
+
+ return wuir;
+}
+
+static void at91_shdwc_dt_configure(struct platform_device *pdev)
+{
+ struct shdwc *shdw = platform_get_drvdata(pdev);
+ struct device_node *np = pdev->dev.of_node;
+ u32 mode = 0, tmp, input;
+
+ if (!np) {
+ dev_err(&pdev->dev, "device node not found\n");
+ return;
+ }
+
+ if (!of_property_read_u32(np, "atmel,shdwc-debouncer", &tmp))
+ mode |= AT91_SHDW_WKUPDBC(at91_shdwc_debouncer_value(pdev, tmp));
+
+ if (of_property_read_bool(np, "atmel,wakeup-rtc-timer"))
+ mode |= SHDW_RTCWKEN(shdw->cfg);
+
+ dev_dbg(&pdev->dev, "%s: mode = %#x\n", __func__, mode);
+ writel(mode, shdw->at91_shdwc_base + AT91_SHDW_MR);
+
+ input = at91_shdwc_get_wakeup_input(pdev, np);
+ writel(input, shdw->at91_shdwc_base + AT91_SHDW_WUIR);
+}
+
+static const struct shdwc_config sama5d2_shdwc_config = {
+ .wkup_pin_input = 0,
+ .mr_rtcwk_shift = 17,
+ .sr_rtcwk_shift = 5,
+};
+
+static const struct of_device_id at91_shdwc_of_match[] = {
+ {
+ .compatible = "atmel,sama5d2-shdwc",
+ .data = &sama5d2_shdwc_config,
+ }, {
+ /*sentinel*/
+ }
+};
+MODULE_DEVICE_TABLE(of, at91_shdwc_of_match);
+
+static int __init at91_shdwc_probe(struct platform_device *pdev)
+{
+ struct resource *res;
+ const struct of_device_id *match;
+ int ret;
+
+ if (!pdev->dev.of_node)
+ return -ENODEV;
+
+ at91_shdwc = devm_kzalloc(&pdev->dev, sizeof(*at91_shdwc), GFP_KERNEL);
+ if (!at91_shdwc)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, at91_shdwc);
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ at91_shdwc->at91_shdwc_base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(at91_shdwc->at91_shdwc_base)) {
+ dev_err(&pdev->dev, "Could not map reset controller address\n");
+ return PTR_ERR(at91_shdwc->at91_shdwc_base);
+ }
+
+ match = of_match_node(at91_shdwc_of_match, pdev->dev.of_node);
+ at91_shdwc->cfg = (struct shdwc_config *)(match->data);
+
+ sclk = devm_clk_get(&pdev->dev, NULL);
+ if (IS_ERR(sclk))
+ return PTR_ERR(sclk);
+
+ ret = clk_prepare_enable(sclk);
+ if (ret) {
+ dev_err(&pdev->dev, "Could not enable slow clock\n");
+ return ret;
+ }
+
+ at91_wakeup_status(pdev);
+
+ at91_shdwc_dt_configure(pdev);
+
+ pm_power_off = at91_poweroff;
+
+ return 0;
+}
+
+static int __exit at91_shdwc_remove(struct platform_device *pdev)
+{
+ struct shdwc *shdw = platform_get_drvdata(pdev);
+
+ if (pm_power_off == at91_poweroff)
+ pm_power_off = NULL;
+
+ /* Reset values to disable wake-up features */
+ writel(0, shdw->at91_shdwc_base + AT91_SHDW_MR);
+ writel(0, shdw->at91_shdwc_base + AT91_SHDW_WUIR);
+
+ clk_disable_unprepare(sclk);
+
+ return 0;
+}
+
+static struct platform_driver at91_shdwc_driver = {
+ .remove = __exit_p(at91_shdwc_remove),
+ .driver = {
+ .name = "at91-shdwc",
+ .of_match_table = at91_shdwc_of_match,
+ },
+};
+module_platform_driver_probe(at91_shdwc_driver, at91_shdwc_probe);
+
+MODULE_AUTHOR("Nicolas Ferre <nicolas.ferre@atmel.com>");
+MODULE_DESCRIPTION("Atmel shutdown controller driver");
+MODULE_LICENSE("GPL v2");
--
2.1.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v3 2/2] power: reset: at91-shdwc: add new shutdown controller driver
2015-09-30 16:22 ` Nicolas Ferre
@ 2015-09-30 16:45 ` kbuild test robot
-1 siblings, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2015-09-30 16:45 UTC (permalink / raw)
To: Nicolas Ferre
Cc: kbuild-all, linux-arm-kernel, sre, Alexandre Belloni, robh+dt,
linux-kernel, Maxime Ripard, linux, mark.rutland, ijc+devicetree,
Jean-Christophe PLAGNIOL-VILLARD, Nicolas Ferre
[-- Attachment #1: Type: text/plain, Size: 3952 bytes --]
Hi Nicolas,
[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]
config: x86_64-allmodconfig (attached as .config)
reproduce:
git checkout c2df3a7df512b1d640247d7c9b7542217bfb9ab1
# save the attached .config to linux build tree
make ARCH=x86_64
All warnings (new ones prefixed by >>):
drivers/power/reset/at91-shdwc.c: In function 'at91_poweroff':
>> drivers/power/reset/at91-shdwc.c:32:24: warning: large integer implicitly truncated to unsigned type [-Woverflow]
#define AT91_SHDW_KEY (0xa5 << 24) /* KEY Password */
^
>> drivers/power/reset/at91-shdwc.c:107:9: note: in expansion of macro 'AT91_SHDW_KEY'
writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
^
vim +32 drivers/power/reset/at91-shdwc.c
26 #include <linux/printk.h>
27
28 #define SLOW_CLOCK_FREQ 32768
29
30 #define AT91_SHDW_CR 0x00 /* Shut Down Control Register */
31 #define AT91_SHDW_SHDW BIT(0) /* Shut Down command */
> 32 #define AT91_SHDW_KEY (0xa5 << 24) /* KEY Password */
33
34 #define AT91_SHDW_MR 0x04 /* Shut Down Mode Register */
35 #define AT91_SHDW_WKUPDBC_SHIFT 24
36 #define AT91_SHDW_WKUPDBC_MASK GENMASK(31, 16)
37 #define AT91_SHDW_WKUPDBC(x) (((x) << AT91_SHDW_WKUPDBC_SHIFT) \
38 & AT91_SHDW_WKUPDBC_MASK)
39
40 #define AT91_SHDW_SR 0x08 /* Shut Down Status Register */
41 #define AT91_SHDW_WKUPIS_SHIFT 16
42 #define AT91_SHDW_WKUPIS_MASK GENMASK(31, 16)
43 #define AT91_SHDW_WKUPIS(x) ((1 << (x)) << AT91_SHDW_WKUPIS_SHIFT \
44 & AT91_SHDW_WKUPIS_MASK)
45
46 #define AT91_SHDW_WUIR 0x0c /* Shutdown Wake-up Inputs Register */
47 #define AT91_SHDW_WKUPEN_MASK GENMASK(15, 0)
48 #define AT91_SHDW_WKUPEN(x) ((1 << (x)) & AT91_SHDW_WKUPEN_MASK)
49 #define AT91_SHDW_WKUPT_SHIFT 16
50 #define AT91_SHDW_WKUPT_MASK GENMASK(31, 16)
51 #define AT91_SHDW_WKUPT(x) ((1 << (x)) << AT91_SHDW_WKUPT_SHIFT \
52 & AT91_SHDW_WKUPT_MASK)
53
54 #define SHDW_WK_PIN(reg, cfg) ((reg) & AT91_SHDW_WKUPIS((cfg)->wkup_pin_input))
55 #define SHDW_RTCWK(reg, cfg) (((reg) >> ((cfg)->sr_rtcwk_shift)) & 0x1)
56 #define SHDW_RTCWKEN(cfg) (1 << ((cfg)->mr_rtcwk_shift))
57
58 #define DBC_PERIOD_US(x) DIV_ROUND_UP_ULL((1000000 * (x)), \
59 SLOW_CLOCK_FREQ)
60
61 struct shdwc_config {
62 u8 wkup_pin_input;
63 u8 mr_rtcwk_shift;
64 u8 sr_rtcwk_shift;
65 };
66
67 struct shdwc {
68 struct shdwc_config *cfg;
69 void __iomem *at91_shdwc_base;
70 };
71
72 /*
73 * Hold configuration here, cannot be more than one instance of the driver
74 * since pm_power_off itself is global.
75 */
76 static struct shdwc *at91_shdwc;
77 static struct clk *sclk;
78
79 static const unsigned long long sdwc_dbc_period[] = {
80 0, 3, 32, 512, 4096, 32768,
81 };
82
83 static void __init at91_wakeup_status(struct platform_device *pdev)
84 {
85 struct shdwc *shdw = platform_get_drvdata(pdev);
86 u32 reg;
87 char *reason = "unknown";
88
89 reg = readl(shdw->at91_shdwc_base + AT91_SHDW_SR);
90
91 dev_dbg(&pdev->dev, "%s: status = %#x\n", __func__, reg);
92
93 /* Simple power-on, just bail out */
94 if (!reg)
95 return;
96
97 if (SHDW_WK_PIN(reg, shdw->cfg))
98 reason = "WKUP pin";
99 else if (SHDW_RTCWK(reg, shdw->cfg))
100 reason = "RTC";
101
102 pr_info("AT91: Wake-Up source: %s\n", reason);
103 }
104
105 static void at91_poweroff(void)
106 {
> 107 writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
108 at91_shdwc->at91_shdwc_base + AT91_SHDW_CR);
109 }
110
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 50064 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 2/2] power: reset: at91-shdwc: add new shutdown controller driver
@ 2015-09-30 16:45 ` kbuild test robot
0 siblings, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2015-09-30 16:45 UTC (permalink / raw)
To: linux-arm-kernel
Hi Nicolas,
[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]
config: x86_64-allmodconfig (attached as .config)
reproduce:
git checkout c2df3a7df512b1d640247d7c9b7542217bfb9ab1
# save the attached .config to linux build tree
make ARCH=x86_64
All warnings (new ones prefixed by >>):
drivers/power/reset/at91-shdwc.c: In function 'at91_poweroff':
>> drivers/power/reset/at91-shdwc.c:32:24: warning: large integer implicitly truncated to unsigned type [-Woverflow]
#define AT91_SHDW_KEY (0xa5 << 24) /* KEY Password */
^
>> drivers/power/reset/at91-shdwc.c:107:9: note: in expansion of macro 'AT91_SHDW_KEY'
writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
^
vim +32 drivers/power/reset/at91-shdwc.c
26 #include <linux/printk.h>
27
28 #define SLOW_CLOCK_FREQ 32768
29
30 #define AT91_SHDW_CR 0x00 /* Shut Down Control Register */
31 #define AT91_SHDW_SHDW BIT(0) /* Shut Down command */
> 32 #define AT91_SHDW_KEY (0xa5 << 24) /* KEY Password */
33
34 #define AT91_SHDW_MR 0x04 /* Shut Down Mode Register */
35 #define AT91_SHDW_WKUPDBC_SHIFT 24
36 #define AT91_SHDW_WKUPDBC_MASK GENMASK(31, 16)
37 #define AT91_SHDW_WKUPDBC(x) (((x) << AT91_SHDW_WKUPDBC_SHIFT) \
38 & AT91_SHDW_WKUPDBC_MASK)
39
40 #define AT91_SHDW_SR 0x08 /* Shut Down Status Register */
41 #define AT91_SHDW_WKUPIS_SHIFT 16
42 #define AT91_SHDW_WKUPIS_MASK GENMASK(31, 16)
43 #define AT91_SHDW_WKUPIS(x) ((1 << (x)) << AT91_SHDW_WKUPIS_SHIFT \
44 & AT91_SHDW_WKUPIS_MASK)
45
46 #define AT91_SHDW_WUIR 0x0c /* Shutdown Wake-up Inputs Register */
47 #define AT91_SHDW_WKUPEN_MASK GENMASK(15, 0)
48 #define AT91_SHDW_WKUPEN(x) ((1 << (x)) & AT91_SHDW_WKUPEN_MASK)
49 #define AT91_SHDW_WKUPT_SHIFT 16
50 #define AT91_SHDW_WKUPT_MASK GENMASK(31, 16)
51 #define AT91_SHDW_WKUPT(x) ((1 << (x)) << AT91_SHDW_WKUPT_SHIFT \
52 & AT91_SHDW_WKUPT_MASK)
53
54 #define SHDW_WK_PIN(reg, cfg) ((reg) & AT91_SHDW_WKUPIS((cfg)->wkup_pin_input))
55 #define SHDW_RTCWK(reg, cfg) (((reg) >> ((cfg)->sr_rtcwk_shift)) & 0x1)
56 #define SHDW_RTCWKEN(cfg) (1 << ((cfg)->mr_rtcwk_shift))
57
58 #define DBC_PERIOD_US(x) DIV_ROUND_UP_ULL((1000000 * (x)), \
59 SLOW_CLOCK_FREQ)
60
61 struct shdwc_config {
62 u8 wkup_pin_input;
63 u8 mr_rtcwk_shift;
64 u8 sr_rtcwk_shift;
65 };
66
67 struct shdwc {
68 struct shdwc_config *cfg;
69 void __iomem *at91_shdwc_base;
70 };
71
72 /*
73 * Hold configuration here, cannot be more than one instance of the driver
74 * since pm_power_off itself is global.
75 */
76 static struct shdwc *at91_shdwc;
77 static struct clk *sclk;
78
79 static const unsigned long long sdwc_dbc_period[] = {
80 0, 3, 32, 512, 4096, 32768,
81 };
82
83 static void __init at91_wakeup_status(struct platform_device *pdev)
84 {
85 struct shdwc *shdw = platform_get_drvdata(pdev);
86 u32 reg;
87 char *reason = "unknown";
88
89 reg = readl(shdw->at91_shdwc_base + AT91_SHDW_SR);
90
91 dev_dbg(&pdev->dev, "%s: status = %#x\n", __func__, reg);
92
93 /* Simple power-on, just bail out */
94 if (!reg)
95 return;
96
97 if (SHDW_WK_PIN(reg, shdw->cfg))
98 reason = "WKUP pin";
99 else if (SHDW_RTCWK(reg, shdw->cfg))
100 reason = "RTC";
101
102 pr_info("AT91: Wake-Up source: %s\n", reason);
103 }
104
105 static void at91_poweroff(void)
106 {
> 107 writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
108 at91_shdwc->at91_shdwc_base + AT91_SHDW_CR);
109 }
110
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/octet-stream
Size: 50064 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151001/6e4e7502/attachment-0001.obj>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 2/2] power: reset: at91-shdwc: add new shutdown controller driver
2015-09-30 16:22 ` Nicolas Ferre
@ 2015-10-01 15:12 ` kbuild test robot
-1 siblings, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2015-10-01 15:12 UTC (permalink / raw)
To: Nicolas Ferre
Cc: kbuild-all, linux-arm-kernel, sre, Alexandre Belloni, robh+dt,
linux-kernel, Maxime Ripard, linux, mark.rutland, ijc+devicetree,
Jean-Christophe PLAGNIOL-VILLARD, Nicolas Ferre
[-- Attachment #1: Type: text/plain, Size: 4510 bytes --]
Hi Nicolas,
[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]
config: ia64-allmodconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout c2df3a7df512b1d640247d7c9b7542217bfb9ab1
# save the attached .config to linux build tree
make.cross ARCH=ia64
All warnings (new ones prefixed by >>):
In file included from include/linux/io.h:25:0,
from drivers/power/reset/at91-shdwc.c:22:
drivers/power/reset/at91-shdwc.c: In function 'at91_poweroff':
arch/ia64/include/asm/io.h:394:30: warning: large integer implicitly truncated to unsigned type [-Woverflow]
#define writel(v,a) __writel((v), (a))
^
>> drivers/power/reset/at91-shdwc.c:107:2: note: in expansion of macro 'writel'
writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
^
vim +/writel +107 drivers/power/reset/at91-shdwc.c
16 * - Analog Comparator wake-up alarm
17 * - Serial RX wake-up alarm
18 * - low power debouncer
19 */
20
21 #include <linux/clk.h>
> 22 #include <linux/io.h>
23 #include <linux/module.h>
24 #include <linux/of.h>
25 #include <linux/platform_device.h>
26 #include <linux/printk.h>
27
28 #define SLOW_CLOCK_FREQ 32768
29
30 #define AT91_SHDW_CR 0x00 /* Shut Down Control Register */
31 #define AT91_SHDW_SHDW BIT(0) /* Shut Down command */
32 #define AT91_SHDW_KEY (0xa5 << 24) /* KEY Password */
33
34 #define AT91_SHDW_MR 0x04 /* Shut Down Mode Register */
35 #define AT91_SHDW_WKUPDBC_SHIFT 24
36 #define AT91_SHDW_WKUPDBC_MASK GENMASK(31, 16)
37 #define AT91_SHDW_WKUPDBC(x) (((x) << AT91_SHDW_WKUPDBC_SHIFT) \
38 & AT91_SHDW_WKUPDBC_MASK)
39
40 #define AT91_SHDW_SR 0x08 /* Shut Down Status Register */
41 #define AT91_SHDW_WKUPIS_SHIFT 16
42 #define AT91_SHDW_WKUPIS_MASK GENMASK(31, 16)
43 #define AT91_SHDW_WKUPIS(x) ((1 << (x)) << AT91_SHDW_WKUPIS_SHIFT \
44 & AT91_SHDW_WKUPIS_MASK)
45
46 #define AT91_SHDW_WUIR 0x0c /* Shutdown Wake-up Inputs Register */
47 #define AT91_SHDW_WKUPEN_MASK GENMASK(15, 0)
48 #define AT91_SHDW_WKUPEN(x) ((1 << (x)) & AT91_SHDW_WKUPEN_MASK)
49 #define AT91_SHDW_WKUPT_SHIFT 16
50 #define AT91_SHDW_WKUPT_MASK GENMASK(31, 16)
51 #define AT91_SHDW_WKUPT(x) ((1 << (x)) << AT91_SHDW_WKUPT_SHIFT \
52 & AT91_SHDW_WKUPT_MASK)
53
54 #define SHDW_WK_PIN(reg, cfg) ((reg) & AT91_SHDW_WKUPIS((cfg)->wkup_pin_input))
55 #define SHDW_RTCWK(reg, cfg) (((reg) >> ((cfg)->sr_rtcwk_shift)) & 0x1)
56 #define SHDW_RTCWKEN(cfg) (1 << ((cfg)->mr_rtcwk_shift))
57
58 #define DBC_PERIOD_US(x) DIV_ROUND_UP_ULL((1000000 * (x)), \
59 SLOW_CLOCK_FREQ)
60
61 struct shdwc_config {
62 u8 wkup_pin_input;
63 u8 mr_rtcwk_shift;
64 u8 sr_rtcwk_shift;
65 };
66
67 struct shdwc {
68 struct shdwc_config *cfg;
69 void __iomem *at91_shdwc_base;
70 };
71
72 /*
73 * Hold configuration here, cannot be more than one instance of the driver
74 * since pm_power_off itself is global.
75 */
76 static struct shdwc *at91_shdwc;
77 static struct clk *sclk;
78
79 static const unsigned long long sdwc_dbc_period[] = {
80 0, 3, 32, 512, 4096, 32768,
81 };
82
83 static void __init at91_wakeup_status(struct platform_device *pdev)
84 {
85 struct shdwc *shdw = platform_get_drvdata(pdev);
86 u32 reg;
87 char *reason = "unknown";
88
89 reg = readl(shdw->at91_shdwc_base + AT91_SHDW_SR);
90
91 dev_dbg(&pdev->dev, "%s: status = %#x\n", __func__, reg);
92
93 /* Simple power-on, just bail out */
94 if (!reg)
95 return;
96
97 if (SHDW_WK_PIN(reg, shdw->cfg))
98 reason = "WKUP pin";
99 else if (SHDW_RTCWK(reg, shdw->cfg))
100 reason = "RTC";
101
102 pr_info("AT91: Wake-Up source: %s\n", reason);
103 }
104
105 static void at91_poweroff(void)
106 {
> 107 writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
108 at91_shdwc->at91_shdwc_base + AT91_SHDW_CR);
109 }
110
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 41024 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 2/2] power: reset: at91-shdwc: add new shutdown controller driver
@ 2015-10-01 15:12 ` kbuild test robot
0 siblings, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2015-10-01 15:12 UTC (permalink / raw)
To: linux-arm-kernel
Hi Nicolas,
[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]
config: ia64-allmodconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout c2df3a7df512b1d640247d7c9b7542217bfb9ab1
# save the attached .config to linux build tree
make.cross ARCH=ia64
All warnings (new ones prefixed by >>):
In file included from include/linux/io.h:25:0,
from drivers/power/reset/at91-shdwc.c:22:
drivers/power/reset/at91-shdwc.c: In function 'at91_poweroff':
arch/ia64/include/asm/io.h:394:30: warning: large integer implicitly truncated to unsigned type [-Woverflow]
#define writel(v,a) __writel((v), (a))
^
>> drivers/power/reset/at91-shdwc.c:107:2: note: in expansion of macro 'writel'
writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
^
vim +/writel +107 drivers/power/reset/at91-shdwc.c
16 * - Analog Comparator wake-up alarm
17 * - Serial RX wake-up alarm
18 * - low power debouncer
19 */
20
21 #include <linux/clk.h>
> 22 #include <linux/io.h>
23 #include <linux/module.h>
24 #include <linux/of.h>
25 #include <linux/platform_device.h>
26 #include <linux/printk.h>
27
28 #define SLOW_CLOCK_FREQ 32768
29
30 #define AT91_SHDW_CR 0x00 /* Shut Down Control Register */
31 #define AT91_SHDW_SHDW BIT(0) /* Shut Down command */
32 #define AT91_SHDW_KEY (0xa5 << 24) /* KEY Password */
33
34 #define AT91_SHDW_MR 0x04 /* Shut Down Mode Register */
35 #define AT91_SHDW_WKUPDBC_SHIFT 24
36 #define AT91_SHDW_WKUPDBC_MASK GENMASK(31, 16)
37 #define AT91_SHDW_WKUPDBC(x) (((x) << AT91_SHDW_WKUPDBC_SHIFT) \
38 & AT91_SHDW_WKUPDBC_MASK)
39
40 #define AT91_SHDW_SR 0x08 /* Shut Down Status Register */
41 #define AT91_SHDW_WKUPIS_SHIFT 16
42 #define AT91_SHDW_WKUPIS_MASK GENMASK(31, 16)
43 #define AT91_SHDW_WKUPIS(x) ((1 << (x)) << AT91_SHDW_WKUPIS_SHIFT \
44 & AT91_SHDW_WKUPIS_MASK)
45
46 #define AT91_SHDW_WUIR 0x0c /* Shutdown Wake-up Inputs Register */
47 #define AT91_SHDW_WKUPEN_MASK GENMASK(15, 0)
48 #define AT91_SHDW_WKUPEN(x) ((1 << (x)) & AT91_SHDW_WKUPEN_MASK)
49 #define AT91_SHDW_WKUPT_SHIFT 16
50 #define AT91_SHDW_WKUPT_MASK GENMASK(31, 16)
51 #define AT91_SHDW_WKUPT(x) ((1 << (x)) << AT91_SHDW_WKUPT_SHIFT \
52 & AT91_SHDW_WKUPT_MASK)
53
54 #define SHDW_WK_PIN(reg, cfg) ((reg) & AT91_SHDW_WKUPIS((cfg)->wkup_pin_input))
55 #define SHDW_RTCWK(reg, cfg) (((reg) >> ((cfg)->sr_rtcwk_shift)) & 0x1)
56 #define SHDW_RTCWKEN(cfg) (1 << ((cfg)->mr_rtcwk_shift))
57
58 #define DBC_PERIOD_US(x) DIV_ROUND_UP_ULL((1000000 * (x)), \
59 SLOW_CLOCK_FREQ)
60
61 struct shdwc_config {
62 u8 wkup_pin_input;
63 u8 mr_rtcwk_shift;
64 u8 sr_rtcwk_shift;
65 };
66
67 struct shdwc {
68 struct shdwc_config *cfg;
69 void __iomem *at91_shdwc_base;
70 };
71
72 /*
73 * Hold configuration here, cannot be more than one instance of the driver
74 * since pm_power_off itself is global.
75 */
76 static struct shdwc *at91_shdwc;
77 static struct clk *sclk;
78
79 static const unsigned long long sdwc_dbc_period[] = {
80 0, 3, 32, 512, 4096, 32768,
81 };
82
83 static void __init at91_wakeup_status(struct platform_device *pdev)
84 {
85 struct shdwc *shdw = platform_get_drvdata(pdev);
86 u32 reg;
87 char *reason = "unknown";
88
89 reg = readl(shdw->at91_shdwc_base + AT91_SHDW_SR);
90
91 dev_dbg(&pdev->dev, "%s: status = %#x\n", __func__, reg);
92
93 /* Simple power-on, just bail out */
94 if (!reg)
95 return;
96
97 if (SHDW_WK_PIN(reg, shdw->cfg))
98 reason = "WKUP pin";
99 else if (SHDW_RTCWK(reg, shdw->cfg))
100 reason = "RTC";
101
102 pr_info("AT91: Wake-Up source: %s\n", reason);
103 }
104
105 static void at91_poweroff(void)
106 {
> 107 writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
108 at91_shdwc->at91_shdwc_base + AT91_SHDW_CR);
109 }
110
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/octet-stream
Size: 41024 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151001/efa7d3a8/attachment-0001.obj>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 1/2] ARM: at91/dt: shdwc binding: add new shutdown controller documentation
2015-09-30 16:22 ` Nicolas Ferre
@ 2015-10-03 17:02 ` Alexandre Belloni
-1 siblings, 0 replies; 14+ messages in thread
From: Alexandre Belloni @ 2015-10-03 17:02 UTC (permalink / raw)
To: Nicolas Ferre
Cc: linux-arm-kernel, sre, robh+dt, linux-kernel, Maxime Ripard,
linux, mark.rutland, ijc+devicetree,
Jean-Christophe PLAGNIOL-VILLARD
On 30/09/2015 at 18:22:00 +0200, Nicolas Ferre wrote :
> +SHDWC Shutdown Controller (Alternative)
> +
> +1) shdwc node
> +
> +required properties:
> +- compatible: should be "atmel,sama5d2-shdwc".
> +- reg: should contain registers location and length
> +- clocks: phandle to input clock.
> +- #address-cells: should be one. The cell is the wake-up input index.
> +- #size-cells: should be zero.
> +
> +optional properties:
> +
> +- atmel,wakeup-debouncer: minimum wake-up inputs debouncer period in
Shouldn't that property be called atmel,wakeup-debouncer-ms ?
> +
> +2) input nodes
> +
> +Wake-up input nodes are usually described in the "board" part of the Device
> +Tree. Note also that input 0 is linked to the wake-up pin and is frequently
> +used.
> +
> +Required properties:
> +- reg: should contain the wake-up input index [0 - 15].
> +
> +Optional properties:
> +- atmel,wakeup-type: string, operation mode of the input described by the child
> + node. Supported values are: "high" or "low".
> +
Maybe we could avoid parsing string and use an integer with a few defines
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 1/2] ARM: at91/dt: shdwc binding: add new shutdown controller documentation
@ 2015-10-03 17:02 ` Alexandre Belloni
0 siblings, 0 replies; 14+ messages in thread
From: Alexandre Belloni @ 2015-10-03 17:02 UTC (permalink / raw)
To: linux-arm-kernel
On 30/09/2015 at 18:22:00 +0200, Nicolas Ferre wrote :
> +SHDWC Shutdown Controller (Alternative)
> +
> +1) shdwc node
> +
> +required properties:
> +- compatible: should be "atmel,sama5d2-shdwc".
> +- reg: should contain registers location and length
> +- clocks: phandle to input clock.
> +- #address-cells: should be one. The cell is the wake-up input index.
> +- #size-cells: should be zero.
> +
> +optional properties:
> +
> +- atmel,wakeup-debouncer: minimum wake-up inputs debouncer period in
Shouldn't that property be called atmel,wakeup-debouncer-ms ?
> +
> +2) input nodes
> +
> +Wake-up input nodes are usually described in the "board" part of the Device
> +Tree. Note also that input 0 is linked to the wake-up pin and is frequently
> +used.
> +
> +Required properties:
> +- reg: should contain the wake-up input index [0 - 15].
> +
> +Optional properties:
> +- atmel,wakeup-type: string, operation mode of the input described by the child
> + node. Supported values are: "high" or "low".
> +
Maybe we could avoid parsing string and use an integer with a few defines
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 1/2] ARM: at91/dt: shdwc binding: add new shutdown controller documentation
2015-10-03 17:02 ` Alexandre Belloni
@ 2016-03-07 14:31 ` Nicolas Ferre
-1 siblings, 0 replies; 14+ messages in thread
From: Nicolas Ferre @ 2016-03-07 14:31 UTC (permalink / raw)
To: Alexandre Belloni, robh+dt, mark.rutland, ijc+devicetree, Pawel Moll
Cc: linux-arm-kernel, sre, linux-kernel, Maxime Ripard, linux,
Jean-Christophe PLAGNIOL-VILLARD
Le 03/10/2015 19:02, Alexandre Belloni a écrit :
> On 30/09/2015 at 18:22:00 +0200, Nicolas Ferre wrote :
>> +SHDWC Shutdown Controller (Alternative)
>> +
>> +1) shdwc node
>> +
>> +required properties:
>> +- compatible: should be "atmel,sama5d2-shdwc".
>> +- reg: should contain registers location and length
>> +- clocks: phandle to input clock.
>> +- #address-cells: should be one. The cell is the wake-up input index.
>> +- #size-cells: should be zero.
>> +
>> +optional properties:
>> +
>> +- atmel,wakeup-debouncer: minimum wake-up inputs debouncer period in
>
> Shouldn't that property be called atmel,wakeup-debouncer-ms ?
Well, as it's microseconds, it should be "-us", according to the file:
Documentation/devicetree/bindings/property-units.txt.
Reworking on this I realised that a kind "generic" property exists for
this type: "debounce-delay-ms", without a vendor prefix.
So, for the DT people, what do you think if I change my private property
to this one that seems to be used in a bunch of bindings already in its
milliseconds variant:
gpio-matrix-keypad.txt, tc3589x.txt, extcon-palmas.txt or with a vendor
prefix in nvidia,tegra20-kbc.txt or lpc32xx-key.txt
and if I diversify it to a "debounce-delay-us" variant and use it in
this driver?
>> +
>> +2) input nodes
>> +
>> +Wake-up input nodes are usually described in the "board" part of the Device
>> +Tree. Note also that input 0 is linked to the wake-up pin and is frequently
>> +used.
>> +
>> +Required properties:
>> +- reg: should contain the wake-up input index [0 - 15].
>> +
>> +Optional properties:
>> +- atmel,wakeup-type: string, operation mode of the input described by the child
>> + node. Supported values are: "high" or "low".
>> +
>
> Maybe we could avoid parsing string and use an integer with a few defines
Yes, even a boolean should do the trick. What about:
- atmel,wakeup-active-high: boolean, the corresponding wake-up
input described by the child, forces the wake-up of the core power
supply on a high level. The default is to be active low.
Thanks for your insights. Best regards,
--
Nicolas Ferre
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 1/2] ARM: at91/dt: shdwc binding: add new shutdown controller documentation
@ 2016-03-07 14:31 ` Nicolas Ferre
0 siblings, 0 replies; 14+ messages in thread
From: Nicolas Ferre @ 2016-03-07 14:31 UTC (permalink / raw)
To: linux-arm-kernel
Le 03/10/2015 19:02, Alexandre Belloni a ?crit :
> On 30/09/2015 at 18:22:00 +0200, Nicolas Ferre wrote :
>> +SHDWC Shutdown Controller (Alternative)
>> +
>> +1) shdwc node
>> +
>> +required properties:
>> +- compatible: should be "atmel,sama5d2-shdwc".
>> +- reg: should contain registers location and length
>> +- clocks: phandle to input clock.
>> +- #address-cells: should be one. The cell is the wake-up input index.
>> +- #size-cells: should be zero.
>> +
>> +optional properties:
>> +
>> +- atmel,wakeup-debouncer: minimum wake-up inputs debouncer period in
>
> Shouldn't that property be called atmel,wakeup-debouncer-ms ?
Well, as it's microseconds, it should be "-us", according to the file:
Documentation/devicetree/bindings/property-units.txt.
Reworking on this I realised that a kind "generic" property exists for
this type: "debounce-delay-ms", without a vendor prefix.
So, for the DT people, what do you think if I change my private property
to this one that seems to be used in a bunch of bindings already in its
milliseconds variant:
gpio-matrix-keypad.txt, tc3589x.txt, extcon-palmas.txt or with a vendor
prefix in nvidia,tegra20-kbc.txt or lpc32xx-key.txt
and if I diversify it to a "debounce-delay-us" variant and use it in
this driver?
>> +
>> +2) input nodes
>> +
>> +Wake-up input nodes are usually described in the "board" part of the Device
>> +Tree. Note also that input 0 is linked to the wake-up pin and is frequently
>> +used.
>> +
>> +Required properties:
>> +- reg: should contain the wake-up input index [0 - 15].
>> +
>> +Optional properties:
>> +- atmel,wakeup-type: string, operation mode of the input described by the child
>> + node. Supported values are: "high" or "low".
>> +
>
> Maybe we could avoid parsing string and use an integer with a few defines
Yes, even a boolean should do the trick. What about:
- atmel,wakeup-active-high: boolean, the corresponding wake-up
input described by the child, forces the wake-up of the core power
supply on a high level. The default is to be active low.
Thanks for your insights. Best regards,
--
Nicolas Ferre
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2016-03-07 14:31 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-30 16:21 [PATCH v3 0/2] power: reset: support for Atmel alternative Shutdown Controller Nicolas Ferre
2015-09-30 16:21 ` Nicolas Ferre
2015-09-30 16:22 ` [PATCH v3 1/2] ARM: at91/dt: shdwc binding: add new shutdown controller documentation Nicolas Ferre
2015-09-30 16:22 ` Nicolas Ferre
2015-10-03 17:02 ` Alexandre Belloni
2015-10-03 17:02 ` Alexandre Belloni
2016-03-07 14:31 ` Nicolas Ferre
2016-03-07 14:31 ` Nicolas Ferre
2015-09-30 16:22 ` [PATCH v3 2/2] power: reset: at91-shdwc: add new shutdown controller driver Nicolas Ferre
2015-09-30 16:22 ` Nicolas Ferre
2015-09-30 16:45 ` kbuild test robot
2015-09-30 16:45 ` kbuild test robot
2015-10-01 15:12 ` kbuild test robot
2015-10-01 15:12 ` kbuild test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.