devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiaxun Yang <jiaxun.yang@flygoat.com>
To: Qing Zhang <zhangqing@loongson.cn>,
	Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	Rob Herring <robh+dt@kernel.org>,
	Huacai Chen <chenhuacai@kernel.org>
Cc: devicetree@vger.kernel.org, linux-mips@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] MIPS: Loongson64: Add Loongson-2K1000 reset support
Date: Mon, 28 Jun 2021 09:12:20 +0800	[thread overview]
Message-ID: <08a4ce65-91e0-122e-6f17-b66e08270350@flygoat.com> (raw)
In-Reply-To: <20210627073806.32564-1-zhangqing@loongson.cn>


在 2021/6/27 下午3:38, Qing Zhang 写道:
> Add power management register operations to support reboot and poweroff.
>
> Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
> ---
>
> v1-v2:
> - Add pm block node
>
> Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
>
> diff --git a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
> index 569e814def83..929e8ddf86eb 100644
> --- a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
> +++ b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
> @@ -101,6 +101,14 @@ uart0: serial@1fe00000 {
>   			no-loopback-test;
>   		};
>   
> +		pm: power-controller {
> +			device_type = "power management";

Hi Qing,

Not compatible?


> +			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";
> diff --git a/arch/mips/loongson64/reset.c b/arch/mips/loongson64/reset.c
> index c97bfdc8c922..ea125e925d44 100644
> --- a/arch/mips/loongson64/reset.c
> +++ b/arch/mips/loongson64/reset.c
> @@ -10,6 +10,7 @@
>   #include <linux/delay.h>
>   #include <linux/init.h>
>   #include <linux/kexec.h>
> +#include <linux/of_address.h>
>   #include <linux/pm.h>
>   #include <linux/slab.h>
>   
> @@ -20,12 +21,50 @@
>   #include <loongson.h>
>   #include <boot_param.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);
> +}

We do have that helper in of_address.h.

Btw, I'd prefer make it as a driver in driver/platform/mips.

Also the approach using PRID to tell protocol type doesn't really make 
sense to me.

You can override _machine_restart callback in diver once FDT node is found.

Thanks.

- Jiaxun

> +
> +static int  __init loongson_fdt_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]);
> +	}
> +
> +	of_node_put(np);
> +	return 0;
> +}
> +arch_initcall(loongson_fdt_reset_init);
> +
>   static void loongson_restart(char *command)
>   {
> +	if ((read_c0_prid() & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64R) {
> +		writel(0x1, (void *)pm_reg_name[2]);
> +	} else {
> +		void (*fw_restart)(void) = (void *)loongson_sysconf.restart_addr;
>   
> -	void (*fw_restart)(void) = (void *)loongson_sysconf.restart_addr;
> +		fw_restart();
> +	}
>   
> -	fw_restart();
>   	while (1) {
>   		if (cpu_wait)
>   			cpu_wait();
> @@ -34,9 +73,18 @@ static void loongson_restart(char *command)
>   
>   static void loongson_poweroff(void)
>   {
> -	void (*fw_poweroff)(void) = (void *)loongson_sysconf.poweroff_addr;
> +	if ((read_c0_prid() & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64R) {
> +		/* 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]);
> +	} else {
> +
> +		void (*fw_poweroff)(void) = (void *)loongson_sysconf.poweroff_addr;
> +
> +		fw_poweroff();
> +	}
>   
> -	fw_poweroff();
>   	while (1) {
>   		if (cpu_wait)
>   			cpu_wait();

  reply	other threads:[~2021-06-28  1:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-27  7:38 [PATCH v2] MIPS: Loongson64: Add Loongson-2K1000 reset support Qing Zhang
2021-06-28  1:12 ` Jiaxun Yang [this message]
2021-06-28  1:44   ` zhangqing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=08a4ce65-91e0-122e-6f17-b66e08270350@flygoat.com \
    --to=jiaxun.yang@flygoat.com \
    --cc=chenhuacai@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=tsbogend@alpha.franken.de \
    --cc=zhangqing@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).