diff mbox series

[RFC,19/25] kvx: power: scall poweroff driver

Message ID 20230103164359.24347-20-ysionneau@kalray.eu
State New
Headers show
Series Upstream kvx Linux port | expand

Commit Message

Yann Sionneau Jan. 3, 2023, 4:43 p.m. UTC
Add a driver to poweroff the Coolidge SoC
when running under Qemu, ISS or when
the debugger (jtag-runner) runs on PL0
to catch the scall.

CC: Sebastian Reichel <sre@kernel.org>
CC: linux-kernel@vger.kernel.org
CC: linux-pm@vger.kernel.org
Co-developed-by: Clement Leger <clement.leger@bootlin.com>
Signed-off-by: Clement Leger <clement.leger@bootlin.com>
Co-developed-by: Julian Vetter <jvetter@kalray.eu>
Signed-off-by: Julian Vetter <jvetter@kalray.eu>
Signed-off-by: Yann Sionneau <ysionneau@kalray.eu>
---
 drivers/power/reset/kvx-scall-poweroff.c | 53 ++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 drivers/power/reset/kvx-scall-poweroff.c

Comments

Sebastian Reichel Jan. 4, 2023, 5:08 p.m. UTC | #1
Hi,

On Tue, Jan 03, 2023 at 05:43:53PM +0100, Yann Sionneau wrote:
> Add a driver to poweroff the Coolidge SoC
> when running under Qemu, ISS or when
> the debugger (jtag-runner) runs on PL0
> to catch the scall.

line length of 41 characters is quite short.

> CC: Sebastian Reichel <sre@kernel.org>
> CC: linux-kernel@vger.kernel.org
> CC: linux-pm@vger.kernel.org
> Co-developed-by: Clement Leger <clement.leger@bootlin.com>
> Signed-off-by: Clement Leger <clement.leger@bootlin.com>
> Co-developed-by: Julian Vetter <jvetter@kalray.eu>
> Signed-off-by: Julian Vetter <jvetter@kalray.eu>
> Signed-off-by: Yann Sionneau <ysionneau@kalray.eu>
> ---
>  drivers/power/reset/kvx-scall-poweroff.c | 53 ++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
>  create mode 100644 drivers/power/reset/kvx-scall-poweroff.c
> 
> diff --git a/drivers/power/reset/kvx-scall-poweroff.c b/drivers/power/reset/kvx-scall-poweroff.c
> new file mode 100644
> index 000000000000..586d93fbcaed
> --- /dev/null
> +++ b/drivers/power/reset/kvx-scall-poweroff.c
> @@ -0,0 +1,53 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2017 - 2022 Kalray Inc.
> + * Author(s): Clement Leger
> + */
> +
> +#include <linux/pm.h>
> +#include <linux/module.h>
> +#include <linux/of_device.h>
> +#include <linux/platform_device.h>
> +
> +#define SCALL_NUM_EXIT	"0xfff"
> +
> +static void kvx_scall_poweroff(void)
> +{
> +	register int status asm("r0") = 0;
> +
> +	asm volatile ("scall " SCALL_NUM_EXIT "\n\t;;"
> +		      : /* out */
> +		      : "r"(status));
> +
> +	unreachable();
> +}
> +
> +static int kvx_scall_poweroff_probe(struct platform_device *pdev)
> +{
> +	pm_power_off = kvx_scall_poweroff;
> +
> +	return 0;
> +}

Please use devm_register_power_off_handler().

-- Sebastian

> +static int kvx_scall_poweroff_remove(struct platform_device *pdev)
> +{
> +	if (pm_power_off == kvx_scall_poweroff)
> +		pm_power_off = NULL;
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id kvx_scall_poweroff_of_match[] = {
> +	{ .compatible = "kalray,kvx-scall-poweroff" },
> +	{}
> +};
> +
> +static struct platform_driver kvx_scall_poweroff_driver = {
> +	.probe = kvx_scall_poweroff_probe,
> +	.remove = kvx_scall_poweroff_remove,
> +	.driver = {
> +		.name = "kvx-scall-poweroff",
> +		.of_match_table = kvx_scall_poweroff_of_match,
> +	},
> +};
> +module_platform_driver(kvx_scall_poweroff_driver);
> -- 
> 2.37.2
> 
> 
> 
> 
>
diff mbox series

Patch

diff --git a/drivers/power/reset/kvx-scall-poweroff.c b/drivers/power/reset/kvx-scall-poweroff.c
new file mode 100644
index 000000000000..586d93fbcaed
--- /dev/null
+++ b/drivers/power/reset/kvx-scall-poweroff.c
@@ -0,0 +1,53 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 - 2022 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#include <linux/pm.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+
+#define SCALL_NUM_EXIT	"0xfff"
+
+static void kvx_scall_poweroff(void)
+{
+	register int status asm("r0") = 0;
+
+	asm volatile ("scall " SCALL_NUM_EXIT "\n\t;;"
+		      : /* out */
+		      : "r"(status));
+
+	unreachable();
+}
+
+static int kvx_scall_poweroff_probe(struct platform_device *pdev)
+{
+	pm_power_off = kvx_scall_poweroff;
+
+	return 0;
+}
+
+static int kvx_scall_poweroff_remove(struct platform_device *pdev)
+{
+	if (pm_power_off == kvx_scall_poweroff)
+		pm_power_off = NULL;
+
+	return 0;
+}
+
+static const struct of_device_id kvx_scall_poweroff_of_match[] = {
+	{ .compatible = "kalray,kvx-scall-poweroff" },
+	{}
+};
+
+static struct platform_driver kvx_scall_poweroff_driver = {
+	.probe = kvx_scall_poweroff_probe,
+	.remove = kvx_scall_poweroff_remove,
+	.driver = {
+		.name = "kvx-scall-poweroff",
+		.of_match_table = kvx_scall_poweroff_of_match,
+	},
+};
+module_platform_driver(kvx_scall_poweroff_driver);