All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] power/reset: zx: Register restart handler
@ 2015-07-06  8:35 Jun Nie
  2015-07-13 12:00 ` Sebastian Reichel
  0 siblings, 1 reply; 4+ messages in thread
From: Jun Nie @ 2015-07-06  8:35 UTC (permalink / raw)
  To: sre, haojian.zhuang, dbaryshkov, dwmw2
  Cc: linux-pm, shawn.guo, wan.zhijun, jason.liu, Jun Nie

Register with kernel restart handler instead of setting arm_pm_restart
directly.

Signed-off-by: Jun Nie <jun.nie@linaro.org>
---
 drivers/power/reset/Kconfig     |  7 ++++
 drivers/power/reset/Makefile    |  1 +
 drivers/power/reset/zx-reboot.c | 82 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+)
 create mode 100644 drivers/power/reset/zx-reboot.c

diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index aad9c33..4ed90f3 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -165,5 +165,12 @@ config POWER_RESET_RMOBILE
 	help
 	  Reboot support for Renesas R-Mobile and SH-Mobile SoCs.
 
+config POWER_RESET_ZX
+	tristate "ZTE SoCs reset driver"
+	depends on ARCH_ZX || COMPILE_TEST
+	depends on HAS_IOMEM
+	help
+	  Reboot support for ZTE SoCs.
+
 endif
 
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index dbe06c3..096fa67 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -19,3 +19,4 @@ 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
+obj-$(CONFIG_POWER_RESET_ZX) += zx-reboot.o
diff --git a/drivers/power/reset/zx-reboot.c b/drivers/power/reset/zx-reboot.c
new file mode 100644
index 0000000..e930a44
--- /dev/null
+++ b/drivers/power/reset/zx-reboot.c
@@ -0,0 +1,82 @@
+/*
+ * ZTE zx296702 SoC reset code
+ *
+ * Copyright (c) 2015 Linaro Ltd.
+ *
+ * Author: Jun Nie <jun.nie@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/reboot.h>
+
+#include <asm/proc-fns.h>
+
+static void __iomem *base;
+static void __iomem *pcu_base;
+
+static int zx_restart_handler(struct notifier_block *this,
+			      unsigned long mode, void *cmd)
+{
+	writel_relaxed(1, base + 0xb0);
+	writel_relaxed(1, pcu_base + 0x34);
+
+	while (1)
+		cpu_do_idle();
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block zx_restart_nb = {
+	.notifier_call = zx_restart_handler,
+	.priority = 128,
+};
+
+static int zx_reboot_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	int err;
+
+	base = of_iomap(np, 0);
+	if (!base) {
+		WARN(1, "failed to map base address");
+		return -ENODEV;
+	}
+
+	np = of_find_compatible_node(NULL, NULL, "zte,zx296702-pcu");
+	pcu_base = of_iomap(np, 0);
+	if (!pcu_base) {
+		iounmap(base);
+		WARN(1, "failed to map pcu_base address");
+		return -ENODEV;
+	}
+
+	err = register_restart_handler(&zx_restart_nb);
+	if (err)
+		dev_err(&pdev->dev, "Register restart handler failed(err=%d)\n",
+			err);
+
+	return err;
+}
+
+static const struct of_device_id zx_reboot_of_match[] = {
+	{ .compatible = "zte,sysctrl" },
+	{}
+};
+
+static struct platform_driver zx_reboot_driver = {
+	.probe = zx_reboot_probe,
+	.driver = {
+		.name = "zx-reboot",
+		.of_match_table = zx_reboot_of_match,
+	},
+};
+module_platform_driver(zx_reboot_driver);
-- 
1.9.1


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

* Re: [PATCH v2] power/reset: zx: Register restart handler
  2015-07-06  8:35 [PATCH v2] power/reset: zx: Register restart handler Jun Nie
@ 2015-07-13 12:00 ` Sebastian Reichel
  2015-07-14  1:42   ` Jun Nie
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Reichel @ 2015-07-13 12:00 UTC (permalink / raw)
  To: Jun Nie
  Cc: haojian.zhuang, dbaryshkov, dwmw2, linux-pm, shawn.guo,
	wan.zhijun, jason.liu

[-- Attachment #1: Type: text/plain, Size: 1446 bytes --]

Hi,

On Mon, Jul 06, 2015 at 04:35:30PM +0800, Jun Nie wrote:
> Register with kernel restart handler instead of setting arm_pm_restart
> directly.
> 
> [...]
>
> +static void __iomem *base;
> +static void __iomem *pcu_base;
> +
> +static int zx_restart_handler(struct notifier_block *this,
> +			      unsigned long mode, void *cmd)
> +{
> +	writel_relaxed(1, base + 0xb0);
> +	writel_relaxed(1, pcu_base + 0x34);
> +
> +	while (1)
> +		cpu_do_idle();

mdelay(some_time);
pr_emerg("Unable to restart system\n");

> +
> +	return NOTIFY_DONE;
> +}
> +
>
> [...]
>
> +static int zx_reboot_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	int err;
> +
> +	base = of_iomap(np, 0);
> +	if (!base) {
> +		WARN(1, "failed to map base address");
> +		return -ENODEV;
> +	}
> +
> +	np = of_find_compatible_node(NULL, NULL, "zte,zx296702-pcu");
> +	pcu_base = of_iomap(np, 0);
> +	if (!pcu_base) {
> +		iounmap(base);
> +		WARN(1, "failed to map pcu_base address");
> +		return -ENODEV;
> +	}
> +
> +	err = register_restart_handler(&zx_restart_nb);
> +	if (err)
> +		dev_err(&pdev->dev, "Register restart handler failed(err=%d)\n",
> +			err);
> +
> +	return err;
> +}
> +
> +static const struct of_device_id zx_reboot_of_match[] = {
> +	{ .compatible = "zte,sysctrl" },
> +	{}
> +};

Where's the DT Binding Documentation?

> [...]

-- Sebastian

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH v2] power/reset: zx: Register restart handler
  2015-07-13 12:00 ` Sebastian Reichel
@ 2015-07-14  1:42   ` Jun Nie
  2015-07-14  6:27     ` Sebastian Reichel
  0 siblings, 1 reply; 4+ messages in thread
From: Jun Nie @ 2015-07-14  1:42 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Haojian Zhuang, Dmitry Eremin-Solenikov, David Woodhouse,
	linux-pm, Shawn Guo, wan.zhijun, Jason Liu

2015-07-13 20:00 GMT+08:00 Sebastian Reichel <sre@kernel.org>:
> Hi,
>
> On Mon, Jul 06, 2015 at 04:35:30PM +0800, Jun Nie wrote:
>> Register with kernel restart handler instead of setting arm_pm_restart
>> directly.
>>
>> [...]
>>
>> +static void __iomem *base;
>> +static void __iomem *pcu_base;
>> +
>> +static int zx_restart_handler(struct notifier_block *this,
>> +                           unsigned long mode, void *cmd)
>> +{
>> +     writel_relaxed(1, base + 0xb0);
>> +     writel_relaxed(1, pcu_base + 0x34);
>> +
>> +     while (1)
>> +             cpu_do_idle();
>
> mdelay(some_time);
> pr_emerg("Unable to restart system\n");

I do not think these code can be executed as reset will happen after
register writing and while loop will stop any further code execution.
Please point out issue if any.

>
>> +
>> +     return NOTIFY_DONE;
>> +}
>> +
>>
>> [...]
>>
>> +static int zx_reboot_probe(struct platform_device *pdev)
>> +{
>> +     struct device_node *np = pdev->dev.of_node;
>> +     int err;
>> +
>> +     base = of_iomap(np, 0);
>> +     if (!base) {
>> +             WARN(1, "failed to map base address");
>> +             return -ENODEV;
>> +     }
>> +
>> +     np = of_find_compatible_node(NULL, NULL, "zte,zx296702-pcu");
>> +     pcu_base = of_iomap(np, 0);
>> +     if (!pcu_base) {
>> +             iounmap(base);
>> +             WARN(1, "failed to map pcu_base address");
>> +             return -ENODEV;
>> +     }
>> +
>> +     err = register_restart_handler(&zx_restart_nb);
>> +     if (err)
>> +             dev_err(&pdev->dev, "Register restart handler failed(err=%d)\n",
>> +                     err);
>> +
>> +     return err;
>> +}
>> +
>> +static const struct of_device_id zx_reboot_of_match[] = {
>> +     { .compatible = "zte,sysctrl" },
>> +     {}
>> +};
>
> Where's the DT Binding Documentation?
DT document is in Documentation/devicetree/bindings/arm/zte.txt

>
>> [...]
>
> -- Sebastian

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

* Re: [PATCH v2] power/reset: zx: Register restart handler
  2015-07-14  1:42   ` Jun Nie
@ 2015-07-14  6:27     ` Sebastian Reichel
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2015-07-14  6:27 UTC (permalink / raw)
  To: Jun Nie
  Cc: Haojian Zhuang, Dmitry Eremin-Solenikov, David Woodhouse,
	linux-pm, Shawn Guo, wan.zhijun, Jason Liu

[-- Attachment #1: Type: text/plain, Size: 1074 bytes --]

Hi,

On Tue, Jul 14, 2015 at 09:42:39AM +0800, Jun Nie wrote:
> 2015-07-13 20:00 GMT+08:00 Sebastian Reichel <sre@kernel.org>:
> > On Mon, Jul 06, 2015 at 04:35:30PM +0800, Jun Nie wrote:
> >> Register with kernel restart handler instead of setting arm_pm_restart
> >> directly.
> >>
> >> [...]
> >>
> >> +static int zx_restart_handler(struct notifier_block *this,
> >> +                           unsigned long mode, void *cmd)
> >> +{
> >> +     writel_relaxed(1, base + 0xb0);
> >> +     writel_relaxed(1, pcu_base + 0x34);
> >> +
> >> +     while (1)
> >> +             cpu_do_idle();
> >
> > mdelay(some_time);
> > pr_emerg("Unable to restart system\n");
> 
> I do not think these code can be executed as reset will happen after
> register writing and while loop will stop any further code execution.
> Please point out issue if any.

Please remove the while loop. Instead wait for a reasonable amount
of time. If something goes wrong print an error message and return
NOTIFY_DONE. You can see an example in syscon-reboot.c

-- Sebastian

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2015-07-14  6:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-06  8:35 [PATCH v2] power/reset: zx: Register restart handler Jun Nie
2015-07-13 12:00 ` Sebastian Reichel
2015-07-14  1:42   ` Jun Nie
2015-07-14  6:27     ` Sebastian Reichel

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.