Skip to contentSkip to conversation

nds32: Power management

PATCH Superseded Nickhu 2 participants 5 messages Oct 24, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nickhu

author
#0 lore raw

cover nds32: Power management

This commit is power management porting for nds32.

Nickhu (1):
nds32: Power management for nds32

 arch/nds32/Kconfig               |  10 +++
 arch/nds32/include/asm/suspend.h |  11 +++
 arch/nds32/kernel/Makefile       |   2 +-
 arch/nds32/kernel/pm.c           |  91 ++++++++++++++++++++++
 arch/nds32/kernel/sleep.S        | 129 +++++++++++++++++++++++++++++++
 drivers/irqchip/irq-ativic32.c   |  29 +++++++
 6 files changed, 271 insertions(+), 1 deletion(-)
 create mode 100644 arch/nds32/include/asm/suspend.h
 create mode 100644 arch/nds32/kernel/pm.c
 create mode 100644 arch/nds32/kernel/sleep.S
Signature · 1 line
2.17.0
author
#1 lore raw

PATCH 1/1 nds32: Power management for nds32

There are three sleep states in nds32:
suspend to idle,
suspend to standby,
suspend to ram

In suspend to ram, we use the 'standby' instruction to emulate power management device to hang the system util wakeup source send wakeup events to break the loop.

First, we push the general purpose registers and system registers to stack. Second, we translate stack pointer to physical address and store to memory to save the stack pointer. Third, after write back and invalid the cache we hang in 'standby' intruction. When wakeup source trigger wake up events, the loop will be break and resume the system.

---
 arch/nds32/Kconfig               |  10 +++
 arch/nds32/include/asm/suspend.h |  11 +++
 arch/nds32/kernel/Makefile       |   2 +-
 arch/nds32/kernel/pm.c           |  91 ++++++++++++++++++++++
 arch/nds32/kernel/sleep.S        | 129 +++++++++++++++++++++++++++++++
 drivers/irqchip/irq-ativic32.c   |  29 +++++++
 6 files changed, 271 insertions(+), 1 deletion(-)
 create mode 100644 arch/nds32/include/asm/suspend.h
 create mode 100644 arch/nds32/kernel/pm.c
 create mode 100644 arch/nds32/kernel/sleep.S
arch/nds32/Kconfig +10 -0
index dd448d431f5a..8e2c5ac6acd1 100644
@@ -95,3 +95,13 @@ endmenu
 menu "Kernel Features"
 source "kernel/Kconfig.hz"
 endmenu
+
+menu "Power management options"
+config SYS_SUPPORTS_APM_EMULATION
+	bool
+
+config ARCH_SUSPEND_POSSIBLE
+	def_bool y
+
+source "kernel/power/Kconfig"
+endmenu
arch/nds32/include/asm/suspend.h new file +11 -0
new file mode 100644
index 000000000000..6ed2418af1ac
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2008-2017 Andes Technology Corporation
+
+#ifndef __ASM_NDS32_SUSPEND_H
+#define __ASM_NDS32_SUSPEND_H
+
+extern void suspend2ram(void);
+extern void cpu_resume(void);
+extern unsigned long wake_mask;
+
+#endif
arch/nds32/kernel/Makefile +1 -1
index f52bd2744f50..8d62f2ecb1ab 100644
@@ -16,7 +16,7 @@ obj-$(CONFIG_STACKTRACE)	+= stacktrace.o
 obj-$(CONFIG_OF)		+= devtree.o
 obj-$(CONFIG_CACHE_L2)		+= atl2c.o
 obj-$(CONFIG_PERF_EVENTS) += perf_event_cpu.o
-
+obj-$(CONFIG_PM)		+= pm.o sleep.o
 extra-y := head.o vmlinux.lds
 
 obj-y				+= vdso/
arch/nds32/kernel/pm.c new file +91 -0

91 lines not on this page · raw message

arch/nds32/kernel/sleep.S new file +129 -0

129 lines not on this page · raw message

drivers/irqchip/irq-ativic32.c +29 -0
index f69a8588521c..3c1a7d0ffc65 100644
@@ -10,6 +10,8 @@
 #include <linux/irqchip.h>
 #include <nds32_intrinsic.h>
 
+unsigned long wake_mask;
+
 static void ativic32_ack_irq(struct irq_data *data)
 {
 	__nds32__mtsr_dsb(BIT(data->hwirq), NDS32_SR_INT_PEND2);
@@ -27,11 +29,38 @@ static void ativic32_unmask_irq(struct irq_data *data)
 	__nds32__mtsr_dsb(int_mask2 | (BIT(data->hwirq)), NDS32_SR_INT_MASK2);
 }
 
+static int nointc_set_wake(struct irq_data *data, unsigned int on)
+{
+	unsigned long int_mask = __nds32__mfsr(NDS32_SR_INT_MASK);
+	static bool is_bit_1[NR_IRQS] = {false};
+	u32 bit = 1 << data->hwirq;
+
+	if (on) {
+		if (int_mask & bit)
+			is_bit_1[data->hwirq] = true;
+		else
+			is_bit_1[data->hwirq] = false;
+
+		int_mask |= bit;
+		wake_mask |= bit;
+	} else {
+		if (!is_bit_1[data->hwirq])
+			int_mask &= ~bit;
+
+		wake_mask &= ~bit;
+		is_bit_1[data->hwirq] = false;
+	}
+
+	__nds32__mtsr_dsb(int_mask, NDS32_SR_INT_MASK);
+	return 0;
+}
+
 static struct irq_chip ativic32_chip = {
 	.name = "ativic32",
 	.irq_ack = ativic32_ack_irq,
 	.irq_mask = ativic32_mask_irq,
 	.irq_unmask = ativic32_unmask_irq,
+	.irq_set_wake = nointc_set_wake,
 };
 
 static unsigned int __initdata nivic_map[6] = { 6, 2, 10, 16, 24, 32 };
Signature · 1 line
2.17.0
#2 lore raw

Re: [PATCH 1/1] nds32: Power management for nds32

Quoted 9 lines · Nickhu

There are three sleep states in nds32:
suspend to idle,
suspend to standby,
suspend to ram

In suspend to ram, we use the 'standby' instruction to emulate power management device to hang the system util wakeup source send wakeup events to break the loop.

Quoted 8 lines

First, we push the general purpose registers and system registers to stack. Second, we translate stack pointer to physical address and store to memory to save the stack pointer. Third, after write back and invalid the cache we hang in 'standby' intruction. When wakeup source trigger wake up events, the loop will be break and resume the system.

Is "Nickhu" complete name?

Quoted 10 lines
arch/nds32/kernel/pm.c new file +4 -0
new file mode 100644
index 000000000000..e1eaf3bac709
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2008-2017 Andes Technology Corporation
+
+/*

arch/nds32/kernel/pm.c line 14

Quoted 10 lines
arch/nds32/kernel/pm.c new file +10 -0
+ * nds32 Power Management Routines
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License.
+ *
+ *  Abstract:
+ *
+ *    This program is for nds32 power management routines.
+ *
+ */

I'd get rid of "abstract" here, repeating GPL twice and "nds32 power management routines" twice does not make much sense either.

arch/nds32/kernel/pm.c line 4

Quoted 5 lines
arch/nds32/kernel/pm.c new file +4 -0
@@ -0,0 +1,129 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2017 Andes Technology Corporation */
+
+#include<asm/memory.h>

Missing space.

Quoted 11 lines
arch/nds32/kernel/pm.c new file +11 -0
+static int nointc_set_wake(struct irq_data *data, unsigned int on)
+{
+	unsigned long int_mask = __nds32__mfsr(NDS32_SR_INT_MASK);
+	static bool is_bit_1[NR_IRQS] = {false};
+	u32 bit = 1 << data->hwirq;
+
+	if (on) {
+		if (int_mask & bit)
+			is_bit_1[data->hwirq] = true;
+		else
+			is_bit_1[data->hwirq] = false;

arch/nds32/kernel/pm.c line 25

Quoted 10 lines
arch/nds32/kernel/pm.c new file +10 -0
+
+		int_mask |= bit;
+		wake_mask |= bit;
+	} else {
+		if (!is_bit_1[data->hwirq])
+			int_mask &= ~bit;
+
+		wake_mask &= ~bit;
+		is_bit_1[data->hwirq] = false;
+	}

Can we get rid of "is_bit_1" array here, and use normal bit operations on another variable here?

Thanks,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#3 lore raw

Re: [PATCH 1/1] nds32: Power management for nds32

Hi Pavel,

Quoted 17 lines · Pavel Machek
Quoted 16 lines · Nickhu

There are three sleep states in nds32:
suspend to idle,
suspend to standby,
suspend to ram

In suspend to ram, we use the 'standby' instruction to emulate power management device to hang the system util wakeup source send wakeup events to break the loop.

First, we push the general purpose registers and system registers to stack. Second, we translate stack pointer to physical address and store to memory to save the stack pointer. Third, after write back and invalid the cache we hang in 'standby' intruction. When wakeup source trigger wake up events, the loop will be break and resume the system.

Quoted 4 lines
Quoted 1 line

Is "Nickhu" complete name?

Oh, Nick Hu is my complete name.
I will fix it.
Thanks!

Quoted 15 lines
Quoted 15 lines
arch/nds32/kernel/pm.c new file +9 -0
new file mode 100644
index 000000000000..e1eaf3bac709
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2008-2017 Andes Technology Corporation
+
+/*
+ * nds32 Power Management Routines
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License.
+ *
Quoted 9 lines

arch/nds32/kernel/pm.c line 14

Quoted 5 lines
arch/nds32/kernel/pm.c new file +5 -0
+ *  Abstract:
+ *
+ *    This program is for nds32 power management routines.
+ *
+ */

I'd get rid of "abstract" here, repeating GPL twice and "nds32 power management routines" twice does not make much sense either.

Ok, I will get rid of it.

Quoted 24 lines

arch/nds32/kernel/pm.c line 4

Quoted 5 lines
arch/nds32/kernel/pm.c new file +4 -0
@@ -0,0 +1,129 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2017 Andes Technology Corporation */
+
+#include<asm/memory.h>

Missing space.

Quoted 16 lines
arch/nds32/kernel/pm.c new file +16 -0
+static int nointc_set_wake(struct irq_data *data, unsigned int on)
+{
+	unsigned long int_mask = __nds32__mfsr(NDS32_SR_INT_MASK);
+	static bool is_bit_1[NR_IRQS] = {false};
+	u32 bit = 1 << data->hwirq;
+
+	if (on) {
+		if (int_mask & bit)
+			is_bit_1[data->hwirq] = true;
+		else
+			is_bit_1[data->hwirq] = false;
+
+		int_mask |= bit;
+		wake_mask |= bit;
+	} else {
+		if (!is_bit_1[data->hwirq])
Quoted 9 lines

arch/nds32/kernel/pm.c line 25

Quoted 5 lines
arch/nds32/kernel/pm.c new file +5 -0
+			int_mask &= ~bit;
+
+		wake_mask &= ~bit;
+		is_bit_1[data->hwirq] = false;
+	}

Can we get rid of "is_bit_1" array here, and use normal bit operations on another variable here?

Do you mean like this:

 static int nointc_set_wake(struct irq_data *data, unsigned int on)  {
        unsigned long int_mask = __nds32__mfsr(NDS32_SR_INT_MASK);
        static unsigned long irq_orig_bit = 0;
        u32 bit = 1 << data->hwirq;

        if (on) {
                if (int_mask & bit)
                        __assign_bit(data->hwirq, &irq_orig_bit, true);
                else
                        __assign_bit(data->hwirq, &irq_orig_bit, false);
 
                __assign_bit(data->hwirq, &int_mask, true);
                __assign_bit(data->hwirq, &wake_mask, true);

        } else {
                if (!(irq_orig_bit & bit))
                        __assign_bit(data->hwirq, &int_mask, false);

                __assign_bit(data->hwirq, &wake_mask, false);
                __assign_bit(data->hwirq, &irq_orig_bit, false);
        }

        __nds32__mtsr_dsb(int_mask, NDS32_SR_INT_MASK);
 
        return 0;

}

Quoted 5 lines

Thanks,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Thank your for quick reply,
Nick Hu.

#4 lore raw

Re: [PATCH 1/1] nds32: Power management for nds32

Hi!

Quoted 23 lines
Quoted 3 lines

Can we get rid of "is_bit_1" array here, and use normal bit operations on another variable here?

Do you mean like this:

 static int nointc_set_wake(struct irq_data *data, unsigned int on)  {
        unsigned long int_mask = __nds32__mfsr(NDS32_SR_INT_MASK);
        static unsigned long irq_orig_bit = 0;
        u32 bit = 1 << data->hwirq;

        if (on) {
                if (int_mask & bit)
                        __assign_bit(data->hwirq, &irq_orig_bit, true);
                else
                        __assign_bit(data->hwirq, &irq_orig_bit, false);
 
                __assign_bit(data->hwirq, &int_mask, true);
                __assign_bit(data->hwirq, &wake_mask, true);

        } else {
                if (!(irq_orig_bit & bit))
                        __assign_bit(data->hwirq, &int_mask, false);
Quoted 7 lines
                __assign_bit(data->hwirq, &wake_mask, false);
                __assign_bit(data->hwirq, &irq_orig_bit, false);
        }

        __nds32__mtsr_dsb(int_mask, NDS32_SR_INT_MASK);
 
        return 0;

Yes, that is better. You don't need = 0 on static variable afaict. (And may want to put it out of a function so it stands out).

You can add my Acked-by on resulting patch.

Thanks,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html