linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers)
@ 2019-07-22 19:53 Evgeny Kolesnikov
  2019-07-22 19:53 ` [PATCH 1/5] power: reset: Add UART-based MCU poweroff DT bindings Evgeny Kolesnikov
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Evgeny Kolesnikov @ 2019-07-22 19:53 UTC (permalink / raw)
  Cc: Evgeny Kolesnikov, Sebastian Reichel, Rob Herring, Mark Rutland,
	Jason Cooper, Andrew Lunn, Gregory Clement,
	Sebastian Hesselbarth, linux-pm, devicetree, linux-kernel,
	linux-arm-kernel

This patchset consists of the DTS, which describes the WD MyCloud EX2 Ultra device,
'poweroff' and 'resert' drivers for power-managing MCUs connected to a board via UART
(these drivers are more versatile than qnap-poweroff and could be used as a substitude),
and DT bindings for these drivers.

The difference between uart-poweroff and qnap-poweroff is small, but important:
uart-poweroff is able to send to an MCU a command of arbitrary length, and the command
itself is defined in a DTS file for a specific device/board, thus making this driver
applicable to wider range of devices.

Evgeny Kolesnikov (5):
  power: reset: Add UART-based MCU poweroff DT bindings
  power: reset: Add UART-based MCU restart DT bindings
  power/reset: Add a power off driver for UART-based PM MCUs
  power/reset: Add a restart driver for UART-based PM MCUs
  ARM: dts: armada385-wd-mcex2u: Add DTS file for WD My Cloud EX2 Ultra

 .../bindings/power/reset/uart-poweroff.txt    |  38 +++
 .../bindings/power/reset/uart-restart.txt     |  39 +++
 arch/arm/boot/dts/armada-385-wd-mcex2u.dts    | 313 ++++++++++++++++++
 drivers/power/reset/Kconfig                   |  14 +
 drivers/power/reset/Makefile                  |   2 +
 drivers/power/reset/uart-poweroff.c           | 155 +++++++++
 drivers/power/reset/uart-restart.c            | 204 ++++++++++++
 7 files changed, 765 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/reset/uart-poweroff.txt
 create mode 100644 Documentation/devicetree/bindings/power/reset/uart-restart.txt
 create mode 100644 arch/arm/boot/dts/armada-385-wd-mcex2u.dts
 create mode 100644 drivers/power/reset/uart-poweroff.c
 create mode 100644 drivers/power/reset/uart-restart.c

-- 
2.21.0


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

* [PATCH 1/5] power: reset: Add UART-based MCU poweroff DT bindings
  2019-07-22 19:53 [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Evgeny Kolesnikov
@ 2019-07-22 19:53 ` Evgeny Kolesnikov
  2019-08-12 23:50   ` Rob Herring
  2019-07-22 19:53 ` [PATCH 2/5] power: reset: Add UART-based MCU restart " Evgeny Kolesnikov
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Evgeny Kolesnikov @ 2019-07-22 19:53 UTC (permalink / raw)
  Cc: Evgeny Kolesnikov, Sebastian Reichel, Rob Herring, Mark Rutland,
	Jason Cooper, Andrew Lunn, Gregory Clement,
	Sebastian Hesselbarth, linux-pm, devicetree, linux-kernel,
	linux-arm-kernel

This adds device tree bindings of the poweroff driver
for power managing micro controller units that are connected
to a board via the UART interface.

Signed-off-by: Evgeny Kolesnikov <evgenyz@gmail.com>
---
 .../bindings/power/reset/uart-poweroff.txt    | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/reset/uart-poweroff.txt

diff --git a/Documentation/devicetree/bindings/power/reset/uart-poweroff.txt b/Documentation/devicetree/bindings/power/reset/uart-poweroff.txt
new file mode 100644
index 000000000000..86d036271b51
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/reset/uart-poweroff.txt
@@ -0,0 +1,38 @@
+* UART-based PM MCU power off driver
+
+Some devices have a microcontroller controlling the main power
+supply. This microcontroller is connected to UART of the SoC.
+Sending a sequence of characters tells the MCU to turn
+the power off.
+
+The length of the sequence, baud rate and the timeout to process
+the command may vary from device to device.
+
+This driver could be used for WD My Cloud (Marvell SoCs), QNAP
+(Kirkwood and Orion5x SoCs) and Synology NAS devices.
+
+Required properties:
+- compatible: Should be "uart-poweroff"
+- reg: Address and length of the register set for UART
+- clocks: The tclk clock
+- cmd: Array of bytes, the command to send to the MCU
+- baud: Baud rate [75..460800]
+
+Optional properties:
+- byte-delay: A delay after each byte of a command, could be useful
+              for sloppy MCUs [ms], default value is 5
+- timeout: A timeout to wait for the MCU to process the command [ms],
+           default value is 1000
+- override: Boolean flag that indicates if the driver should
+            prioritize itself over any existing power off driver,
+            default behaviour is not to interfere
+
+Example:
+	poweroff@12100 {
+		compatible = "uart-poweroff";
+		reg = <0x12100 0x100>;
+		clocks = <&coreclk 0>;
+		baud = <19200>;
+		cmd = [fa 03 03 01 00 00 fb];
+		status = "okay";
+	};
-- 
2.21.0


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

* [PATCH 2/5] power: reset: Add UART-based MCU restart DT bindings
  2019-07-22 19:53 [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Evgeny Kolesnikov
  2019-07-22 19:53 ` [PATCH 1/5] power: reset: Add UART-based MCU poweroff DT bindings Evgeny Kolesnikov
@ 2019-07-22 19:53 ` Evgeny Kolesnikov
  2019-07-22 19:53 ` [PATCH 3/5] power/reset: Add a power off driver for UART-based PM MCUs Evgeny Kolesnikov
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Evgeny Kolesnikov @ 2019-07-22 19:53 UTC (permalink / raw)
  Cc: Evgeny Kolesnikov, Sebastian Reichel, Rob Herring, Mark Rutland,
	Jason Cooper, Andrew Lunn, Gregory Clement,
	Sebastian Hesselbarth, linux-pm, devicetree, linux-kernel,
	linux-arm-kernel

This adds device tree bindings of the restart driver
for power managing micro controller units that are connected
to a board via the UART interface.

Signed-off-by: Evgeny Kolesnikov <evgenyz@gmail.com>
---
 .../bindings/power/reset/uart-restart.txt     | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/reset/uart-restart.txt

diff --git a/Documentation/devicetree/bindings/power/reset/uart-restart.txt b/Documentation/devicetree/bindings/power/reset/uart-restart.txt
new file mode 100644
index 000000000000..bf831d9bdff8
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/reset/uart-restart.txt
@@ -0,0 +1,39 @@
+* UART-based PM MCU restart driver
+
+Some devices have a microcontroller controlling the main power
+supply. This microcontroller is connected to UART of the SoC.
+Sending a sequence of characters tells the MCU to reset the SoC
+and/or MCU itself.
+
+The length of the sequence, baud rate and the timeout to process
+the command may vary from device to device.
+
+This driver could be used for WD My Cloud (Marvell SoCs), QNAP
+(Kirkwood and Orion5x SoCs) and Synology NAS devices.
+
+Required properties:
+- compatible: Should be "uart-restart"
+- reg: Address and length of the register set for UART
+- clocks: The tclk clock
+- cmd: Array of bytes, the command to send to the MCU
+- baud: Baud rate [75..460800]
+
+Optional properties:
+- byte-delay: A delay after each byte of a command, could be useful
+              for sloppy MCUs [ms], default value is 5
+- timeout: A timeout to wait for the MCU to process the command [ms],
+           default value is 1000
+- override: Boolean flag that indicates if the driver should
+            prioritize itself over any existing restart driver,
+            default behaviour is not to interfere
+
+Example:
+	restart@12100 {
+		compatible = "uart-restart";
+		reg = <0x12100 0x100>;
+		clocks = <&coreclk 0>;
+		baud = <19200>;
+		cmd = [fa 03 03 02 00 00 fb];
+		override;
+		status = "okay";
+	};
-- 
2.21.0


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

* [PATCH 3/5] power/reset: Add a power off driver for UART-based PM MCUs
  2019-07-22 19:53 [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Evgeny Kolesnikov
  2019-07-22 19:53 ` [PATCH 1/5] power: reset: Add UART-based MCU poweroff DT bindings Evgeny Kolesnikov
  2019-07-22 19:53 ` [PATCH 2/5] power: reset: Add UART-based MCU restart " Evgeny Kolesnikov
@ 2019-07-22 19:53 ` Evgeny Kolesnikov
  2019-07-22 19:53 ` [PATCH 4/5] power/reset: Add a restart " Evgeny Kolesnikov
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Evgeny Kolesnikov @ 2019-07-22 19:53 UTC (permalink / raw)
  Cc: Evgeny Kolesnikov, Sebastian Reichel, Rob Herring, Mark Rutland,
	Jason Cooper, Andrew Lunn, Gregory Clement,
	Sebastian Hesselbarth, linux-pm, devicetree, linux-kernel,
	linux-arm-kernel

This adds the poweroff driver for power managing
micro controller units that are connected to a board
via the UART interface.

Signed-off-by: Evgeny Kolesnikov <evgenyz@gmail.com>
---
 drivers/power/reset/Kconfig         |   7 ++
 drivers/power/reset/Makefile        |   1 +
 drivers/power/reset/uart-poweroff.c | 155 ++++++++++++++++++++++++++++
 3 files changed, 163 insertions(+)
 create mode 100644 drivers/power/reset/uart-poweroff.c

diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index a564237278ff..02fdf45e3988 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -216,6 +216,13 @@ config POWER_RESET_RMOBILE
 	help
 	  Reboot support for Renesas R-Mobile and SH-Mobile SoCs.
 
+config POWER_RESET_UART_POWEROFF
+	tristate "UART-based PM MCU power off driver"
+	depends on OF_GPIO
+	help
+	  Power off support for boards with UART-based PM MCU
+	  such as WD My Cloud NAS, QNAP Turbo NAS, Synology devices.
+
 config POWER_RESET_ZX
 	tristate "ZTE SoCs reset driver"
 	depends on ARCH_ZX || COMPILE_TEST
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 85da3198e4e0..efe8f25f463d 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -25,6 +25,7 @@ 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_UART_POWEROFF) += uart-poweroff.o
 obj-$(CONFIG_POWER_RESET_ZX) += zx-reboot.o
 obj-$(CONFIG_REBOOT_MODE) += reboot-mode.o
 obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o
diff --git a/drivers/power/reset/uart-poweroff.c b/drivers/power/reset/uart-poweroff.c
new file mode 100644
index 000000000000..8122a6b306d7
--- /dev/null
+++ b/drivers/power/reset/uart-poweroff.c
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Power off for boards with UART-based PM MCUs
+ * such as WD My Cloud NAS, QNAP Turbo NAS, Synology devices.
+ *
+ * Copyright (C) 2019 Evgeny Kolesnikov <evgenyz@gmail.com>
+ *
+ * Based on the code from:
+ *
+ * Copyright (C) 2016 Martin Mueller <mm@sig21.net>
+ * Copyright (C) 2012 Andrew Lunn <andrew@lunn.ch>
+ * Copyright (C) 2009 Martin Michlmayr <tbm@cyrius.com>
+ * Copyright (C) 2008 Byron Bradley <byron.bbradley@gmail.com>
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/serial_reg.h>
+#include <linux/kallsyms.h>
+#include <linux/of.h>
+#include <linux/io.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+
+#define UART_REG(b, x)	(b + ((UART_##x) << 2))
+
+struct uart_poweroff {
+	const u8 *cmd;
+	int cmd_len;
+	void __iomem *base;
+	unsigned int divisor;
+	u32 byte_delay_ms;
+	u32 timeout_ms;
+};
+
+static void *pm_power_off_org;
+static struct uart_poweroff uart_poweroff;
+
+static void uart_power_off(void)
+{
+	int i;
+
+	/* Hijack UART and reset into sane state */
+	writel(0x83, UART_REG(uart_poweroff.base, LCR));
+	writel(uart_poweroff.divisor & 0xFF, UART_REG(uart_poweroff.base, DLL));
+	writel((uart_poweroff.divisor >> 8) & 0xFF, UART_REG(uart_poweroff.base, DLM));
+	writel(0x03, UART_REG(uart_poweroff.base, LCR));
+	writel(0x00, UART_REG(uart_poweroff.base, IER));
+	writel(0x00, UART_REG(uart_poweroff.base, FCR));
+	writel(0x00, UART_REG(uart_poweroff.base, MCR));
+
+	/* Send the command */
+	for (i = 0; i < uart_poweroff.cmd_len; i++) {
+		writel(uart_poweroff.cmd[i], UART_REG(uart_poweroff.base, TX));
+		mdelay(uart_poweroff.byte_delay_ms);
+	}
+
+	mdelay(uart_poweroff.timeout_ms);
+	WARN_ON(1);
+}
+
+static int uart_poweroff_probe(struct platform_device *pdev)
+{
+	struct resource *res;
+	static void __iomem *base;
+	struct clk *clk;
+	u32 baud;
+	bool override;
+	char symname[KSYM_NAME_LEN];
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "Missing resource\n");
+		return -EINVAL;
+	}
+
+	base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+	if (!base) {
+		dev_err(&pdev->dev, "Unable to map resource\n");
+		return -EINVAL;
+	}
+
+	/* We need to know tclk in order to calculate the UART divisor */
+	clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(clk)) {
+		dev_err(&pdev->dev, "Clk missing\n");
+		return PTR_ERR(clk);
+	}
+
+	uart_poweroff.cmd = of_get_property(pdev->dev.of_node, "cmd",
+						&uart_poweroff.cmd_len);
+	if (uart_poweroff.cmd == NULL || uart_poweroff.cmd_len < 1) {
+		dev_err(&pdev->dev, "Cmd is missing or empty\n");
+		return -EINVAL;
+	}
+
+	of_property_read_u32(pdev->dev.of_node, "baud", &baud);
+	if (baud < 75 || baud > 460800) {
+		dev_err(&pdev->dev, "Baud rate is missing or invalid\n");
+		return -EINVAL;
+	}
+
+	uart_poweroff.base = base;
+	uart_poweroff.divisor =
+		((clk_get_rate(clk) + (8 * baud)) / (16 * baud));
+	uart_poweroff.byte_delay_ms = 5;
+	uart_poweroff.timeout_ms = 1000;
+	of_property_read_u32(pdev->dev.of_node, "byte-delay",
+				&uart_poweroff.byte_delay_ms);
+	of_property_read_u32(pdev->dev.of_node, "timeout",
+				&uart_poweroff.timeout_ms);
+
+	override = of_property_read_bool(pdev->dev.of_node, "override");
+
+	if (pm_power_off && !override) {
+		lookup_symbol_name((ulong)pm_power_off, symname);
+		dev_err(&pdev->dev,
+			"The pm_power_off is already claimed by %s (%p) and override is false",
+			symname, pm_power_off);
+		return -EBUSY;
+	}
+	pm_power_off_org = pm_power_off;
+	pm_power_off = uart_power_off;
+
+	return 0;
+}
+
+static int uart_poweroff_remove(struct platform_device *pdev)
+{
+	if (pm_power_off == uart_power_off)
+		pm_power_off = pm_power_off_org;
+
+	return 0;
+}
+
+static const struct of_device_id of_uart_poweroff_match[] = {
+	{ .compatible = "uart-poweroff", },
+	{},
+};
+
+static struct platform_driver uart_poweroff_driver = {
+	.probe	= uart_poweroff_probe,
+	.remove	= uart_poweroff_remove,
+	.driver	= {
+		.name	= "uart_poweroff",
+		.of_match_table = of_uart_poweroff_match,
+	},
+};
+module_platform_driver(uart_poweroff_driver);
+
+MODULE_AUTHOR("Evgeny Kolesnikov <evgenyz@gmail.com>");
+MODULE_DESCRIPTION("UART-based PM MCU power off driver");
+MODULE_LICENSE("GPL v2");
-- 
2.21.0


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

* [PATCH 4/5] power/reset: Add a restart driver for UART-based PM MCUs
  2019-07-22 19:53 [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Evgeny Kolesnikov
                   ` (2 preceding siblings ...)
  2019-07-22 19:53 ` [PATCH 3/5] power/reset: Add a power off driver for UART-based PM MCUs Evgeny Kolesnikov
@ 2019-07-22 19:53 ` Evgeny Kolesnikov
  2019-07-22 19:53 ` [PATCH 5/5] ARM: dts: armada385-wd-mcex2u: Add DTS file for WD My Cloud EX2 Ultra Evgeny Kolesnikov
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Evgeny Kolesnikov @ 2019-07-22 19:53 UTC (permalink / raw)
  Cc: Evgeny Kolesnikov, Sebastian Reichel, Rob Herring, Mark Rutland,
	Jason Cooper, Andrew Lunn, Gregory Clement,
	Sebastian Hesselbarth, linux-pm, devicetree, linux-kernel,
	linux-arm-kernel

This adds the restart driver for power managing
micro controller units that are connected to a board
via the UART interface.

Signed-off-by: Evgeny Kolesnikov <evgenyz@gmail.com>
---
 drivers/power/reset/Kconfig        |   7 +
 drivers/power/reset/Makefile       |   1 +
 drivers/power/reset/uart-restart.c | 204 +++++++++++++++++++++++++++++
 3 files changed, 212 insertions(+)
 create mode 100644 drivers/power/reset/uart-restart.c

diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 02fdf45e3988..4b187af1fba6 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -223,6 +223,13 @@ config POWER_RESET_UART_POWEROFF
 	  Power off support for boards with UART-based PM MCU
 	  such as WD My Cloud NAS, QNAP Turbo NAS, Synology devices.
 
+config POWER_RESET_UART
+	tristate "UART-based PM MCU restart driver"
+	depends on OF_GPIO
+	help
+	  Reboot support for boards with UART-based PM MCU
+	  such as WD My Cloud NAS, QNAP Turbo NAS, Synology devices.
+
 config POWER_RESET_ZX
 	tristate "ZTE SoCs reset driver"
 	depends on ARCH_ZX || COMPILE_TEST
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index efe8f25f463d..fa8a936d7a1a 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -26,6 +26,7 @@ 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_UART_POWEROFF) += uart-poweroff.o
+obj-$(CONFIG_POWER_RESET_UART) += uart-restart.o
 obj-$(CONFIG_POWER_RESET_ZX) += zx-reboot.o
 obj-$(CONFIG_REBOOT_MODE) += reboot-mode.o
 obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o
diff --git a/drivers/power/reset/uart-restart.c b/drivers/power/reset/uart-restart.c
new file mode 100644
index 000000000000..be4dcbbb826e
--- /dev/null
+++ b/drivers/power/reset/uart-restart.c
@@ -0,0 +1,204 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Restart for boards with UART-based PM MCUs
+ * such as WD My Cloud NAS, QNAP Turbo NAS, Synology devices.
+ *
+ * Copyright (C) 2019 Evgeny Kolesnikov <evgenyz@gmail.com>
+ *
+ * Based on the code from:
+ *
+ * Copyright (C) 2016 Martin Mueller <mm@sig21.net>
+ * Copyright (C) 2012 Andrew Lunn <andrew@lunn.ch>
+ * Copyright (C) 2009 Martin Michlmayr <tbm@cyrius.com>
+ * Copyright (C) 2008 Byron Bradley <byron.bbradley@gmail.com>
+ *
+ */
+
+#include <linux/reboot.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/serial_reg.h>
+#include <linux/kallsyms.h>
+#include <linux/of.h>
+#include <linux/io.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#ifdef CONFIG_ARM
+#include <asm/system_misc.h>
+#endif
+
+#define UART_REG(b, x)	(b + ((UART_##x) << 2))
+
+
+struct uart_restart {
+	struct notifier_block restart_handler;
+	const u8 *cmd;
+	int cmd_len;
+	void __iomem *base;
+	unsigned int divisor;
+	u32 byte_delay_ms;
+	u32 timeout_ms;
+	void *pm_restart_org;
+};
+
+static int uart_restart_notify(struct notifier_block *this,
+				unsigned long mode, void *cmd)
+{
+	struct uart_restart *uart_restart =
+		container_of(this, struct uart_restart, restart_handler);
+	int i;
+
+	/* Hijack UART and reset into sane state */
+	writel(0x83, UART_REG(uart_restart->base, LCR));
+	writel(uart_restart->divisor & 0xFF, UART_REG(uart_restart->base, DLL));
+	writel((uart_restart->divisor >> 8) & 0xFF, UART_REG(uart_restart->base, DLM));
+	writel(0x03, UART_REG(uart_restart->base, LCR));
+	writel(0x00, UART_REG(uart_restart->base, IER));
+	writel(0x00, UART_REG(uart_restart->base, FCR));
+	writel(0x00, UART_REG(uart_restart->base, MCR));
+
+	/* Send the command */
+	for (i = 0; i < uart_restart->cmd_len; i++) {
+		writel(uart_restart->cmd[i], UART_REG(uart_restart->base, TX));
+		mdelay(uart_restart->byte_delay_ms);
+	}
+	mdelay(uart_restart->timeout_ms);
+	WARN_ON(1);
+
+	return NOTIFY_DONE;
+}
+
+static int uart_restart_probe(struct platform_device *pdev)
+{
+	struct uart_restart *uart_restart;
+	struct resource *res;
+	void __iomem *base;
+	struct clk *clk;
+	u32 baud;
+	bool override;
+	int err;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "Missing resource\n");
+		return -EINVAL;
+	}
+
+	base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+	if (!base) {
+		dev_err(&pdev->dev, "Unable to map resource\n");
+		return -EINVAL;
+	}
+
+	/* We need to know tclk in order to calculate the UART divisor */
+	clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(clk)) {
+		dev_err(&pdev->dev, "Clk missing\n");
+		return PTR_ERR(clk);
+	}
+
+	uart_restart = devm_kzalloc(&pdev->dev, sizeof(*uart_restart),
+			GFP_KERNEL);
+	if (!uart_restart)
+		return -ENOMEM;
+
+	uart_restart->cmd = of_get_property(pdev->dev.of_node, "cmd",
+						&uart_restart->cmd_len);
+	if (uart_restart->cmd == NULL || uart_restart->cmd_len < 1) {
+		dev_err(&pdev->dev, "Cmd is missing or empty\n");
+		return -EINVAL;
+	}
+
+	of_property_read_u32(pdev->dev.of_node, "baud", &baud);
+	if (baud < 75 || baud > 460800) {
+		dev_err(&pdev->dev, "Baud rate is missing or invalid\n");
+		return -EINVAL;
+	}
+
+	uart_restart->restart_handler.notifier_call = uart_restart_notify;
+	uart_restart->restart_handler.priority = 129;
+	uart_restart->base = base;
+	uart_restart->divisor =
+		((clk_get_rate(clk) + (8 * baud)) / (16 * baud));
+	uart_restart->byte_delay_ms = 5;
+	uart_restart->timeout_ms = 1000;
+	of_property_read_u32(pdev->dev.of_node, "byte-delay",
+				&uart_restart->byte_delay_ms);
+	of_property_read_u32(pdev->dev.of_node, "timeout",
+				&uart_restart->timeout_ms);
+
+	override = of_property_read_bool(pdev->dev.of_node, "override");
+
+	if (override)
+		uart_restart->restart_handler.priority = 192;
+
+	platform_set_drvdata(pdev, uart_restart);
+
+#ifdef CONFIG_ARM
+	char symname[KSYM_NAME_LEN];
+
+	if (arm_pm_restart && !override) {
+		lookup_symbol_name((ulong)arm_pm_restart, symname);
+		dev_err(&pdev->dev,
+			"The arm_pm_restart is already claimed by %s (%p) and override is false",
+			symname, arm_pm_restart);
+		return -EBUSY;
+	}
+#endif
+
+	err = register_restart_handler(&uart_restart->restart_handler);
+	if (err) {
+		dev_err(&pdev->dev,
+			"Unable to register restart handler: %d\n", err);
+		return -ENODEV;
+	}
+
+#ifdef CONFIG_ARM
+	if (arm_pm_restart && override) {
+		uart_restart->pm_restart_org = arm_pm_restart;
+		arm_pm_restart = NULL;
+	}
+#endif
+
+	return 0;
+}
+
+static int uart_restart_remove(struct platform_device *pdev)
+{
+	struct uart_restart *uart_restart = platform_get_drvdata(pdev);
+	int err;
+
+	err = unregister_restart_handler(&uart_restart->restart_handler);
+	if (err) {
+		dev_err(&pdev->dev,
+			"Unable to unregister restart handler, %d\n", err);
+		return -ENODEV;
+	}
+
+#ifdef CONFIG_ARM
+	if (arm_pm_restart == NULL && uart_restart->pm_restart_org != NULL)
+		arm_pm_restart = uart_restart->pm_restart_org;
+#endif
+
+	return 0;
+}
+
+static const struct of_device_id of_uart_restart_match[] = {
+	{ .compatible = "uart-restart", },
+	{},
+};
+
+static struct platform_driver uart_restart_driver = {
+	.probe	= uart_restart_probe,
+	.remove	= uart_restart_remove,
+	.driver	= {
+		.name	= "uart_restart",
+		.of_match_table = of_uart_restart_match,
+	},
+};
+module_platform_driver(uart_restart_driver);
+
+MODULE_AUTHOR("Evgeny Kolesnikov <evgenyz@gmail.com>");
+MODULE_DESCRIPTION("UART-based PM MCU restart driver");
+MODULE_LICENSE("GPL v2");
-- 
2.21.0


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

* [PATCH 5/5] ARM: dts: armada385-wd-mcex2u: Add DTS file for WD My Cloud EX2 Ultra
  2019-07-22 19:53 [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Evgeny Kolesnikov
                   ` (3 preceding siblings ...)
  2019-07-22 19:53 ` [PATCH 4/5] power/reset: Add a restart " Evgeny Kolesnikov
@ 2019-07-22 19:53 ` Evgeny Kolesnikov
  2019-07-23 13:48   ` Andrew Lunn
  2019-07-23  1:56 ` [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Andrew Lunn
  2019-07-28 13:20 ` Pavel Machek
  6 siblings, 1 reply; 12+ messages in thread
From: Evgeny Kolesnikov @ 2019-07-22 19:53 UTC (permalink / raw)
  Cc: Evgeny Kolesnikov, Sebastian Reichel, Rob Herring, Mark Rutland,
	Jason Cooper, Andrew Lunn, Gregory Clement,
	Sebastian Hesselbarth, linux-pm, devicetree, linux-kernel,
	linux-arm-kernel

Add the DTS file to describe the Western Digital My Cloud EX2 Ultra NAS.

Signed-off-by: Evgeny Kolesnikov <evgenyz@gmail.com>
---
 arch/arm/boot/dts/armada-385-wd-mcex2u.dts | 313 +++++++++++++++++++++
 1 file changed, 313 insertions(+)
 create mode 100644 arch/arm/boot/dts/armada-385-wd-mcex2u.dts

diff --git a/arch/arm/boot/dts/armada-385-wd-mcex2u.dts b/arch/arm/boot/dts/armada-385-wd-mcex2u.dts
new file mode 100644
index 000000000000..018e66adbb93
--- /dev/null
+++ b/arch/arm/boot/dts/armada-385-wd-mcex2u.dts
@@ -0,0 +1,313 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/*
+ * Device Tree file for Western Digital My Cloud EX2 Ultra
+ * (BVBZ/Ranger Peak)
+ *
+ * Copyright (C) 2019 Evgeny Kolesnikov <evgenyz@gmail.com>
+ *
+ * Based on the code from:
+ *
+ * Copyright (C) 2016 Martin Mueller <mm@sig21.net>
+ * Copyright (C) 2013 Gregory CLEMENT <gregory.clement@free-electrons.com>
+ * Copyright (C) 2013 Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+ */
+
+/dts-v1/;
+#include <dt-bindings/input/input.h>
+#include <dt-bindings/gpio/gpio.h>
+#include "armada-385.dtsi"
+
+/ {
+	model = "WD My Cloud EX2 Ultra (BVBZ/Ranger Peak)";
+	compatible = "wd,mcex2u", "marvell,armada385", "marvell,armada380";
+
+	chosen {
+		stdout-path = "serial0:115200n8";
+		bootargs = "console=ttyS0,115200";
+	};
+
+	memory {
+		device_type = "memory";
+		reg = <0x00000000 0x40000000>; /* 1024 MB */
+	};
+
+	soc {
+		ranges = <MBUS_ID(0xf0, 0x01) 0 0xf1000000 0x100000
+			  MBUS_ID(0x01, 0x1d) 0 0xfff00000 0x100000
+			  MBUS_ID(0x09, 0x19) 0 0xf1100000 0x10000
+			  MBUS_ID(0x09, 0x15) 0 0xf1110000 0x10000
+			  MBUS_ID(0x0c, 0x04) 0 0xf1200000 0x100000>;
+
+		internal-regs {
+			timer@c200 {
+				status = "disabled";
+			};
+
+			i2c0: i2c@11000 {
+				status = "okay";
+				clock-frequency = <100000>;
+			};
+
+			i2c1: i2c@11100 {
+				status = "okay";
+				clock-frequency = <100000>;
+			};
+
+			serial@12000 {
+				status = "okay";
+			};
+
+			/* Connected to Welltrend 6703F-OG240WT MCU
+			 * which controls power, fan and other things
+			 */
+			serial@12100 {
+				status = "okay";
+			};
+
+			poweroff@12100 {
+				compatible = "uart-poweroff";
+				reg = <0x12100 0x100>;
+				clocks = <&coreclk 0>;
+				baud = <19200>;
+				cmd = [fa 03 03 01 00 00 fb];
+				status = "okay";
+			};
+
+			restart@12100 {
+				compatible = "uart-restart";
+				reg = <0x12100 0x100>;
+				clocks = <&coreclk 0>;
+				baud = <19200>;
+				cmd = [fa 03 03 02 00 00 fb];
+				override;
+				status = "okay";
+			};
+
+			pinctrl@18000 {
+				uart1_pins: uart-pins-1 {
+					marvell,pins = "mpp19";
+					marvell,function = "ua1";
+				};
+
+				xhci0_vbus_pins: xhci0-vbus-pins {
+					marvell,pins = "mpp26";
+					marvell,function = "gpio";
+				};
+
+				xhci1_vbus_pins: xhci1-vbus-pins {
+					marvell,pins = "mpp27";
+					marvell,function = "gpio";
+				};
+
+				sata0_pins: sata-pins-0 {
+					marvell,pins = "mpp55";
+					marvell,function = "sata0";
+				};
+
+				sata1_pins: sata-pins-1 {
+					marvell,pins = "mpp56";
+					marvell,function = "sata1";
+				};
+
+				sata_leds: sata-leds {
+					marvell,pins = "mpp43", "mpp52",
+						       "mpp53", "mpp54";
+					marvell,function = "gpio";
+				};
+
+				btn_pins: btn-pins {
+					marvell,pins = "mpp50";
+					marvell,function = "gpio";
+				};
+			};
+
+			ethernet@34000 {
+				phy = <&phy0>;
+				phy-mode = "sgmii";
+				buffer-manager = <&bm>;
+				bm,pool-long = <0>;
+				bm,pool-short = <1>;
+				status = "okay";
+			};
+
+			usb@58000 {
+				status = "okay";
+			};
+
+			mdio@72004 {
+				phy0: ethernet-phy@0 {
+					/* Init ETH LEDs */
+					marvell,reg-init = <3 16 0 0x101e>;
+					reg = <0>;
+				};
+			};
+
+			crypto@9d000 {
+				status = "okay";
+			};
+
+			rtc@a3800 {
+				status = "okay";
+			};
+
+			sata@a8000 {
+				status = "okay";
+			};
+
+			bm@c8000 {
+				status = "okay";
+			};
+
+			nand-controller@d0000 {
+				status = "okay";
+
+				nand: nand@0 {
+					reg = <0>;
+					label = "pxa3xx_nand-0";
+					marvell,nand-keep-config;
+					nand-rb = <0>;
+					nand-on-flash-bbt;
+					nand-ecc-strength = <4>;
+					nand-ecc-step-size = <512>;
+
+					partitions {
+						compatible = "fixed-partitions";
+						#address-cells = <1>;
+						#size-cells = <1>;
+
+						partition@0000000 {
+							label = "U-Boot";
+							reg = <0x00000000 0x00500000>;
+							read-only;
+						};
+						partition@0500000 {
+							label = "kernel";
+							reg = <0x00500000 0x00500000>;
+						};
+						partition@0a00000 {
+							label = "uRamdisk";
+							reg = <0x00a00000 0x00500000>;
+							read-only;
+						};
+						partition@0f00000 {
+							label = "ubi";
+							reg = <0x00f00000 0x0b900000>;
+						};
+						partition@c800000 {
+							label = "Recovery";
+							reg = <0x0c800000 0x00f00000>;
+							read-only;
+						};
+						partition@d700000 {
+							label = "config";
+							reg = <0x0d700000 0x01400000>;
+						};
+						partition@eb00000 {
+							label = "reserve1";
+							reg = <0x0eb00000 0x00a00000>;
+							read-only;
+						};
+						partition@f500000 {
+							label = "reserve2";
+							reg = <0x0f500000 0x00a00000>;
+							read-only;
+						};
+					};
+				};
+			};
+
+			sdhci@d8000 {
+				status = "disabled";
+			};
+
+			usb3@f0000 {
+				usb-phy = <&usb3_0_phy>;
+				status = "okay";
+			};
+
+			usb3@f8000 {
+				usb-phy = <&usb3_1_phy>;
+				status = "okay";
+			};
+		};
+
+		bm-bppi {
+			status = "okay";
+		};
+	};
+
+	gpio-leds {
+		compatible = "gpio-leds";
+		pinctrl-names = "default";
+		pinctrl-0 = <&sata_leds>;
+
+		sata1-red-led {
+			label = "wdmcex2u:red:hdd1";
+			gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>;
+		};
+		sata2-red-led {
+			label = "wdmcex2u:red:hdd2";
+			gpios = <&gpio1 20 GPIO_ACTIVE_HIGH>;
+		};
+		sata1-blue-led {
+			label = "wdmcex2u:blue:hdd1";
+			gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>;
+			linux,default-trigger = "default-on";
+		};
+		sata2-blue-led {
+			label = "wdmcex2u:blue:hdd2";
+			gpios = <&gpio1 22 GPIO_ACTIVE_HIGH>;
+			linux,default-trigger = "default-on";
+		};
+	};
+
+	gpio-keys {
+		compatible = "gpio-keys";
+		pinctrl-names = "default";
+		pinctrl-0 = <&btn_pins>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reset {
+			label = "reset";
+			linux,code = <KEY_RESTART>;
+			gpios = <&gpio1 18 GPIO_ACTIVE_LOW>;
+			debounce-interval = <60>;
+			wakeup-source;
+		};
+	};
+
+	usb3_0_phy: usb3_0_phy {
+		compatible = "usb-nop-xceiv";
+		vcc-supply = <&reg_usb3_0_vbus>;
+	};
+
+	usb3_1_phy: usb3_1_phy {
+		compatible = "usb-nop-xceiv";
+		vcc-supply = <&reg_usb3_1_vbus>;
+	};
+
+	reg_usb3_0_vbus: usb3-vbus0 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb3-vbus0";
+		pinctrl-names = "default";
+		pinctrl-0 = <&xhci0_vbus_pins>;
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		enable-active-high;
+		regulator-always-on;
+		gpio = <&gpio0 26 GPIO_ACTIVE_HIGH>;
+	};
+
+	reg_usb3_1_vbus: usb3-vbus1 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb3-vbus1";
+		pinctrl-names = "default";
+		pinctrl-0 = <&xhci1_vbus_pins>;
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		enable-active-high;
+		regulator-always-on;
+		gpio = <&gpio0 27 GPIO_ACTIVE_HIGH>;
+	};
+};
-- 
2.21.0


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

* Re: [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers)
  2019-07-22 19:53 [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Evgeny Kolesnikov
                   ` (4 preceding siblings ...)
  2019-07-22 19:53 ` [PATCH 5/5] ARM: dts: armada385-wd-mcex2u: Add DTS file for WD My Cloud EX2 Ultra Evgeny Kolesnikov
@ 2019-07-23  1:56 ` Andrew Lunn
  2019-07-23 17:48   ` Evgeny Kolesnikov
  2019-07-28 13:20 ` Pavel Machek
  6 siblings, 1 reply; 12+ messages in thread
From: Andrew Lunn @ 2019-07-23  1:56 UTC (permalink / raw)
  To: Evgeny Kolesnikov
  Cc: Mark Rutland, Jason Cooper, linux-pm, Gregory Clement,
	Sebastian Reichel, linux-kernel, devicetree, Rob Herring,
	linux-arm-kernel, Sebastian Hesselbarth

On Mon, Jul 22, 2019 at 09:53:00PM +0200, Evgeny Kolesnikov wrote:
> This patchset consists of the DTS, which describes the WD MyCloud EX2 Ultra device,
> 'poweroff' and 'resert' drivers for power-managing MCUs connected to a board via UART
> (these drivers are more versatile than qnap-poweroff and could be used as a substitude),
> and DT bindings for these drivers.
> 
> The difference between uart-poweroff and qnap-poweroff is small, but important:
> uart-poweroff is able to send to an MCU a command of arbitrary length, and the command
> itself is defined in a DTS file for a specific device/board, thus making this driver
> applicable to wider range of devices.

Hi Evgeny

There is a lot of replicated code here, and in the original
qnap-poweroff.c driver. Please consolidate it by extending the current
driver. It should be easy to add a new compatible string, and turn
power_off_cfg.cmd into an array.

	  Andrew

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

* Re: [PATCH 5/5] ARM: dts: armada385-wd-mcex2u: Add DTS file for WD My Cloud EX2 Ultra
  2019-07-22 19:53 ` [PATCH 5/5] ARM: dts: armada385-wd-mcex2u: Add DTS file for WD My Cloud EX2 Ultra Evgeny Kolesnikov
@ 2019-07-23 13:48   ` Andrew Lunn
  0 siblings, 0 replies; 12+ messages in thread
From: Andrew Lunn @ 2019-07-23 13:48 UTC (permalink / raw)
  To: Evgeny Kolesnikov
  Cc: Sebastian Reichel, Rob Herring, Mark Rutland, Jason Cooper,
	Gregory Clement, Sebastian Hesselbarth, linux-pm, devicetree,
	linux-kernel, linux-arm-kernel

> +		internal-regs {
> +			timer@c200 {
> +				status = "disabled";
> +			};
> +
> +			i2c0: i2c@11000 {
> +				status = "okay";
> +				clock-frequency = <100000>;
> +			};
> +
> +			i2c1: i2c@11100 {
> +				status = "okay";
> +				clock-frequency = <100000>;
> +			};

It is a bit unusual to enable i2c busses when there is nothing on
them.

> +			ethernet@34000 {
> +				phy = <&phy0>;

phy has been deprecated. Please use phy-handle.

    Andrew

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

* Re: [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers)
  2019-07-23  1:56 ` [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Andrew Lunn
@ 2019-07-23 17:48   ` Evgeny Kolesnikov
  2019-07-23 22:06     ` Andrew Lunn
  0 siblings, 1 reply; 12+ messages in thread
From: Evgeny Kolesnikov @ 2019-07-23 17:48 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Mark Rutland, Jason Cooper, linux-pm, Gregory Clement,
	Sebastian Reichel, linux-kernel, devicetree, Rob Herring,
	linux-arm-kernel, Sebastian Hesselbarth

On 23/07/2019 03:56, Andrew Lunn wrote:
> On Mon, Jul 22, 2019 at 09:53:00PM +0200, Evgeny Kolesnikov wrote:
>>
>> The difference between uart-poweroff and qnap-poweroff is small, but important:
>> uart-poweroff is able to send to an MCU a command of arbitrary length, and the command
>> itself is defined in a DTS file for a specific device/board, thus making this driver
>> applicable to wider range of devices.
> 
> There is a lot of replicated code here, and in the original
> qnap-poweroff.c driver. Please consolidate it by extending the current
> driver. It should be easy to add a new compatible string, and turn
> power_off_cfg.cmd into an array.

Hi, Andrew.

I've considered extending qnap driver, but I have some doubts about this 
approach.

First of all there is only a poweroff counterpart. As there is no
qnap-restart driver, what should I do with uart-restart? Is it OK to 
have xxx-restart-poweroff driver (never saw anything like that)?

While I can add cmd as a parameter to qnap driver (having it converted
into an array) it should be optional as original qnap relies on two 
hardcoded values for its devices. And having a non-qnap device with this 
driver in DT without defined cmd would not make any sense. It feels 
kinda ugly.

Wouldn't it be more fitting to have these two generic drivers and then 
retire old qnap driver while moving everything that uses it to the new one?

Thanks for the review.

EK.

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

* Re: [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers)
  2019-07-23 17:48   ` Evgeny Kolesnikov
@ 2019-07-23 22:06     ` Andrew Lunn
  0 siblings, 0 replies; 12+ messages in thread
From: Andrew Lunn @ 2019-07-23 22:06 UTC (permalink / raw)
  To: Evgeny Kolesnikov
  Cc: Mark Rutland, Jason Cooper, linux-pm, Gregory Clement,
	Sebastian Reichel, linux-kernel, devicetree, Rob Herring,
	linux-arm-kernel, Sebastian Hesselbarth

On Tue, Jul 23, 2019 at 07:48:49PM +0200, Evgeny Kolesnikov wrote:
> On 23/07/2019 03:56, Andrew Lunn wrote:
> >On Mon, Jul 22, 2019 at 09:53:00PM +0200, Evgeny Kolesnikov wrote:
> >>
> >>The difference between uart-poweroff and qnap-poweroff is small, but important:
> >>uart-poweroff is able to send to an MCU a command of arbitrary length, and the command
> >>itself is defined in a DTS file for a specific device/board, thus making this driver
> >>applicable to wider range of devices.
> >
> >There is a lot of replicated code here, and in the original
> >qnap-poweroff.c driver. Please consolidate it by extending the current
> >driver. It should be easy to add a new compatible string, and turn
> >power_off_cfg.cmd into an array.
> 
> Hi, Andrew.
> 
> I've considered extending qnap driver, but I have some doubts about this
> approach.
> 
> First of all there is only a poweroff counterpart. As there is no
> qnap-restart driver, what should I do with uart-restart? Is it OK to have
> xxx-restart-poweroff driver (never saw anything like that)?

Hi Evgeny

There are a few options. You can refactor all the code into a library
and small drivers which wrap around the library. Or you can make the
driver handle both, using the compatible string to determine which it
should do.
 
> While I can add cmd as a parameter to qnap driver (having it converted
> into an array) it should be optional as original qnap relies on two
> hardcoded values for its devices.

That is not what i meant. You can make the current code more generic
by changing the single byte in power_off_cfg to an array. DT should
describe the hardware, not bytes you poke into registers. So it is
perfectly valid to have the bytes hard coded in the driver.

	  Andrew

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

* Re: [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers)
  2019-07-22 19:53 [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Evgeny Kolesnikov
                   ` (5 preceding siblings ...)
  2019-07-23  1:56 ` [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Andrew Lunn
@ 2019-07-28 13:20 ` Pavel Machek
  6 siblings, 0 replies; 12+ messages in thread
From: Pavel Machek @ 2019-07-28 13:20 UTC (permalink / raw)
  To: Evgeny Kolesnikov
  Cc: Sebastian Reichel, Rob Herring, Mark Rutland, Jason Cooper,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth, linux-pm,
	devicetree, linux-kernel, linux-arm-kernel

On Mon 2019-07-22 21:53:00, Evgeny Kolesnikov wrote:
> This patchset consists of the DTS, which describes the WD MyCloud EX2 Ultra device,
> 'poweroff' and 'resert' drivers for power-managing MCUs connected to a board via UART
> (these drivers are more versatile than qnap-poweroff and could be used as a substitude),
> and DT bindings for these drivers.
> 
> The difference between uart-poweroff and qnap-poweroff is small, but important:
> uart-poweroff is able to send to an MCU a command of arbitrary length, and the command
> itself is defined in a DTS file for a specific device/board, thus making this driver
> applicable to wider range of devices.
> 
>  drivers/power/reset/uart-poweroff.c           | 155 +++++++++
>  drivers/power/reset/uart-restart.c            | 204 ++++++++++++

These twon really need to be combined somehow.

Plus... does it have mini-16550 driver in it? Should it use serdev instead?
										Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [PATCH 1/5] power: reset: Add UART-based MCU poweroff DT bindings
  2019-07-22 19:53 ` [PATCH 1/5] power: reset: Add UART-based MCU poweroff DT bindings Evgeny Kolesnikov
@ 2019-08-12 23:50   ` Rob Herring
  0 siblings, 0 replies; 12+ messages in thread
From: Rob Herring @ 2019-08-12 23:50 UTC (permalink / raw)
  To: Evgeny Kolesnikov
  Cc: Sebastian Reichel, Mark Rutland, Jason Cooper, Andrew Lunn,
	Gregory Clement, Sebastian Hesselbarth, linux-pm, devicetree,
	linux-kernel, linux-arm-kernel

On Mon, Jul 22, 2019 at 09:53:01PM +0200, Evgeny Kolesnikov wrote:
> This adds device tree bindings of the poweroff driver
> for power managing micro controller units that are connected
> to a board via the UART interface.
> 
> Signed-off-by: Evgeny Kolesnikov <evgenyz@gmail.com>
> ---
>  .../bindings/power/reset/uart-poweroff.txt    | 38 +++++++++++++++++++
>  1 file changed, 38 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/power/reset/uart-poweroff.txt
> 
> diff --git a/Documentation/devicetree/bindings/power/reset/uart-poweroff.txt b/Documentation/devicetree/bindings/power/reset/uart-poweroff.txt
> new file mode 100644
> index 000000000000..86d036271b51
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power/reset/uart-poweroff.txt
> @@ -0,0 +1,38 @@
> +* UART-based PM MCU power off driver
> +
> +Some devices have a microcontroller controlling the main power
> +supply. This microcontroller is connected to UART of the SoC.
> +Sending a sequence of characters tells the MCU to turn
> +the power off.

IMO, you should have a node representing the specific microcontroller. 
Generic binding attempts like this generally don't work well because you 
need a never ending addition of properties to deal with h/w (and f/w in 
this case) differences. The properties you already have are evidence of 
this.

Now, if you want a common driver, then that is a separate issue. You can 
have multiple, specific bindings map to a common driver (or not, it's up 
to the OS).

Rob

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

end of thread, other threads:[~2019-08-12 23:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22 19:53 [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Evgeny Kolesnikov
2019-07-22 19:53 ` [PATCH 1/5] power: reset: Add UART-based MCU poweroff DT bindings Evgeny Kolesnikov
2019-08-12 23:50   ` Rob Herring
2019-07-22 19:53 ` [PATCH 2/5] power: reset: Add UART-based MCU restart " Evgeny Kolesnikov
2019-07-22 19:53 ` [PATCH 3/5] power/reset: Add a power off driver for UART-based PM MCUs Evgeny Kolesnikov
2019-07-22 19:53 ` [PATCH 4/5] power/reset: Add a restart " Evgeny Kolesnikov
2019-07-22 19:53 ` [PATCH 5/5] ARM: dts: armada385-wd-mcex2u: Add DTS file for WD My Cloud EX2 Ultra Evgeny Kolesnikov
2019-07-23 13:48   ` Andrew Lunn
2019-07-23  1:56 ` [PATCH 0/5] Add support for WD MyCloud EX2 Ultra (+ versatile UART-based restart/poweroff drivers) Andrew Lunn
2019-07-23 17:48   ` Evgeny Kolesnikov
2019-07-23 22:06     ` Andrew Lunn
2019-07-28 13:20 ` Pavel Machek

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).