All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/2] MIPS: Loongson64: Add Loongson-2K1000 reset platform driver
@ 2021-06-28 15:13 Qing Zhang
  2021-06-28 15:13 ` [PATCH v4 2/2] MIPS: Loongson64: Add pm block node for Loongson-2K1000 Qing Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Qing Zhang @ 2021-06-28 15:13 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Rob Herring, Jiaxun Yang, Huacai Chen
  Cc: devicetree, linux-mips, linux-kernel

Add power management register operations to support reboot and poweroff.

Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
---

v2-v3:
-make reset support as a driver

v3-v4:
-Modify patch title

Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
---
 drivers/platform/mips/Kconfig      |  6 +++
 drivers/platform/mips/Makefile     |  1 +
 drivers/platform/mips/ls2k-reset.c | 60 ++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+)
 create mode 100644 drivers/platform/mips/ls2k-reset.c

diff --git a/drivers/platform/mips/Kconfig b/drivers/platform/mips/Kconfig
index 8ac149173c64..d421e1482395 100644
--- a/drivers/platform/mips/Kconfig
+++ b/drivers/platform/mips/Kconfig
@@ -30,4 +30,10 @@ config RS780E_ACPI
 	help
 	  Loongson RS780E PCH ACPI Controller driver.
 
+config LS2K_RESET
+	bool "Loongson-2K1000 Reset Controller"
+	depends on MACH_LOONGSON64 || COMPILE_TEST
+	help
+	  Loongson-2K1000 Reset Controller driver.
+
 endif # MIPS_PLATFORM_DEVICES
diff --git a/drivers/platform/mips/Makefile b/drivers/platform/mips/Makefile
index 178149098777..4c71444e453a 100644
--- a/drivers/platform/mips/Makefile
+++ b/drivers/platform/mips/Makefile
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_CPU_HWMON) += cpu_hwmon.o
 obj-$(CONFIG_RS780E_ACPI) += rs780e-acpi.o
+obj-$(CONFIG_LS2K_RESET) += ls2k-reset.o
diff --git a/drivers/platform/mips/ls2k-reset.c b/drivers/platform/mips/ls2k-reset.c
new file mode 100644
index 000000000000..c5f073c82c5e
--- /dev/null
+++ b/drivers/platform/mips/ls2k-reset.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ *  Copyright (C) 2021, Qing Zhang <zhangqing@loongson.cn>
+ *  Loongson-2K1000 reset support
+ */
+
+#include <linux/of_address.h>
+#include <linux/pm.h>
+#include <asm/reboot.h>
+
+static char *pm_reg_name[] = {"pm1_sts", "pm1_cnt", "rst_cnt"};
+
+static void __iomem *get_reg_byname(struct device_node *node, const char *name)
+{
+	int index = of_property_match_string(node, "reg-names", name);
+
+	if (index < 0)
+		return NULL;
+
+	return of_iomap(node, index);
+}
+
+static void ls2k_restart(char *command)
+{
+	writel(0x1, (void *)pm_reg_name[2]);
+}
+
+static void ls2k_poweroff(void)
+{
+	/* Clear */
+	writel((readl((void *)pm_reg_name[0]) & 0xffffffff), (void *)pm_reg_name[0]);
+	/* Sleep Enable | Soft Off*/
+	writel(GENMASK(12, 10)|BIT(13), (void *)pm_reg_name[1]);
+}
+
+static int ls2k_reset_init(void)
+{
+	struct device_node *np;
+	int i;
+
+	np = of_find_node_by_type(NULL, "power management");
+	if (!np) {
+		pr_info("Failed to get PM node\n");
+		return -ENODEV;
+	}
+
+	for (i = 0; i < sizeof(pm_reg_name)/sizeof(char *); i++) {
+		pm_reg_name[i] = get_reg_byname(np, pm_reg_name[i]);
+		if (!pm_reg_name[i])
+			iounmap(pm_reg_name[i]);
+	}
+
+	_machine_restart = ls2k_restart;
+	pm_power_off = ls2k_poweroff;
+
+	of_node_put(np);
+	return 0;
+}
+
+arch_initcall(ls2k_reset_init);
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v4 2/2] MIPS: Loongson64: Add pm block node for Loongson-2K1000
  2021-06-28 15:13 [PATCH v4 1/2] MIPS: Loongson64: Add Loongson-2K1000 reset platform driver Qing Zhang
@ 2021-06-28 15:13 ` Qing Zhang
  2021-06-28 16:03   ` Sergei Shtylyov
  0 siblings, 1 reply; 4+ messages in thread
From: Qing Zhang @ 2021-06-28 15:13 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Rob Herring, Jiaxun Yang, Huacai Chen
  Cc: devicetree, linux-mips, linux-kernel

The module is now supported, enable it.

Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
---

v3-v4:
No change

Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
---
 arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
index 569e814def83..e31176ac0ac2 100644
--- a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
+++ b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
@@ -101,6 +101,15 @@ uart0: serial@1fe00000 {
 			no-loopback-test;
 		};
 
+		pm: power-controller {
+			device_type = "power management";
+			compatible = "loongson, reset-controller";
+			reg = <0 0x1fe0700c 0 0x8>,
+				<0 0x1fe07014 0 0x8>,
+				<0 0x1fe07030 0 0x8>;
+			reg-names = "pm1_sts", "pm1_cnt", "rst_cnt";
+		};
+
 		pci@1a000000 {
 			compatible = "loongson,ls2k-pci";
 			device_type = "pci";
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 2/2] MIPS: Loongson64: Add pm block node for Loongson-2K1000
  2021-06-28 15:13 ` [PATCH v4 2/2] MIPS: Loongson64: Add pm block node for Loongson-2K1000 Qing Zhang
@ 2021-06-28 16:03   ` Sergei Shtylyov
  2021-06-29  1:04     ` zhangqing
  0 siblings, 1 reply; 4+ messages in thread
From: Sergei Shtylyov @ 2021-06-28 16:03 UTC (permalink / raw)
  To: Qing Zhang, Thomas Bogendoerfer, Rob Herring, Jiaxun Yang, Huacai Chen
  Cc: devicetree, linux-mips, linux-kernel

Hello!

On 6/28/21 6:13 PM, Qing Zhang wrote:

> The module is now supported, enable it.
> 
> Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
> ---
> 
> v3-v4:
> No change
> 
> Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
> ---
>  arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
> index 569e814def83..e31176ac0ac2 100644
> --- a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
> +++ b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
> @@ -101,6 +101,15 @@ uart0: serial@1fe00000 {
>  			no-loopback-test;
>  		};
>  
> +		pm: power-controller {
> +			device_type = "power management";
> +			compatible = "loongson, reset-controller";

   No spaces allowed here, AFAIK.

> +			reg = <0 0x1fe0700c 0 0x8>,
> +				<0 0x1fe07014 0 0x8>,
> +				<0 0x1fe07030 0 0x8>;

   Better keep those aligned...

> +			reg-names = "pm1_sts", "pm1_cnt", "rst_cnt";
> +		};
> +
[...]

MBR, Sergei

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 2/2] MIPS: Loongson64: Add pm block node for Loongson-2K1000
  2021-06-28 16:03   ` Sergei Shtylyov
@ 2021-06-29  1:04     ` zhangqing
  0 siblings, 0 replies; 4+ messages in thread
From: zhangqing @ 2021-06-29  1:04 UTC (permalink / raw)
  To: Sergei Shtylyov, Thomas Bogendoerfer, Rob Herring, Jiaxun Yang,
	Huacai Chen
  Cc: devicetree, linux-mips, linux-kernel



On 06/29/2021 12:03 AM, Sergei Shtylyov wrote:
> Hello!
>
> On 6/28/21 6:13 PM, Qing Zhang wrote:
>
>> The module is now supported, enable it.
>>
>> Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
>> ---
>>
>> v3-v4:
>> No change
>>
>> Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
>> ---
>>   arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi | 9 +++++++++
>>   1 file changed, 9 insertions(+)
>>
>> diff --git a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
>> index 569e814def83..e31176ac0ac2 100644
>> --- a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
>> +++ b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
>> @@ -101,6 +101,15 @@ uart0: serial@1fe00000 {
>>   			no-loopback-test;
>>   		};
>>   
>> +		pm: power-controller {
>> +			device_type = "power management";
>> +			compatible = "loongson, reset-controller";
>     No spaces allowed here, AFAIK.
>
>> +			reg = <0 0x1fe0700c 0 0x8>,
>> +				<0 0x1fe07014 0 0x8>,
>> +				<0 0x1fe07030 0 0x8>;
>     Better keep those aligned...
Hi Sergei :-)

enm...

Will fix in next reversion.

Thanks.

-Qing
>
>> +			reg-names = "pm1_sts", "pm1_cnt", "rst_cnt";
>> +		};
>> +
> [...]
>
> MBR, Sergei


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-29  1:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-28 15:13 [PATCH v4 1/2] MIPS: Loongson64: Add Loongson-2K1000 reset platform driver Qing Zhang
2021-06-28 15:13 ` [PATCH v4 2/2] MIPS: Loongson64: Add pm block node for Loongson-2K1000 Qing Zhang
2021-06-28 16:03   ` Sergei Shtylyov
2021-06-29  1:04     ` zhangqing

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.