linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: pawel.moll@arm.com (Pawel Moll)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 09/13] ARM: vexpress: Reset driver
Date: Tue, 18 Sep 2012 15:17:51 +0100	[thread overview]
Message-ID: <1347977875-16855-10-git-send-email-pawel.moll@arm.com> (raw)
In-Reply-To: <1347977875-16855-1-git-send-email-pawel.moll@arm.com>

This is a simple driver providing platform restart and power off
functions using VE config infrastructure.

By writing to the "active" attribute of the reboot or reset device,
user can decide what if the platform is supposed to execute full power
cycle (reboot, default) or simply assert system level reset signal.

Signed-off-by: Pawel Moll <pawel.moll@arm.com>
---
 arch/arm/mach-vexpress/reset.c |  141 ++++++++++++++++++++++++++++++++++++++++
 include/linux/vexpress.h       |    3 +
 2 files changed, 144 insertions(+)
 create mode 100644 arch/arm/mach-vexpress/reset.c

diff --git a/arch/arm/mach-vexpress/reset.c b/arch/arm/mach-vexpress/reset.c
new file mode 100644
index 0000000..465923a
--- /dev/null
+++ b/arch/arm/mach-vexpress/reset.c
@@ -0,0 +1,141 @@
+/*
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Copyright (C) 2012 ARM Limited
+ */
+
+#include <linux/jiffies.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/stat.h>
+#include <linux/vexpress.h>
+
+static void vexpress_reset_do(struct device *dev, const char *what)
+{
+	int err = -ENOENT;
+	struct vexpress_config_func *func =
+			vexpress_config_func_get_by_dev(dev);
+
+	if (func) {
+		unsigned long timeout;
+
+		err = vexpress_config_write(func, 0, 0);
+
+		timeout = jiffies + HZ;
+		while (time_before(jiffies, timeout))
+			cpu_relax();
+	}
+
+	dev_emerg(dev, "Unable to %s (%d)\n", what, err);
+}
+
+static struct device *vexpress_power_off_device;
+
+void vexpress_power_off(void)
+{
+	vexpress_reset_do(vexpress_power_off_device, "power off");
+}
+
+static struct device *vexpress_restart_device;
+
+void vexpress_restart(char str, const char *cmd)
+{
+	vexpress_reset_do(vexpress_restart_device, "restart");
+}
+
+static ssize_t vexpress_reset_active_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", vexpress_restart_device == dev);
+}
+
+static ssize_t vexpress_reset_active_store(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t count)
+{
+	long value;
+	int err = kstrtol(buf, 0, &value);
+
+	if (!err && value)
+		vexpress_restart_device = dev;
+
+	return err ? err : count;
+}
+
+DEVICE_ATTR(active, S_IRUGO | S_IWUSR, vexpress_reset_active_show,
+		vexpress_reset_active_store);
+
+
+enum vexpress_reset_func { FUNC_RESET, FUNC_SHUTDOWN, FUNC_REBOOT };
+
+static struct of_device_id vexpress_reset_of_match[] = {
+	{
+		.compatible = "arm,vexpress-reset",
+		.data = (void *)FUNC_RESET,
+	}, {
+		.compatible = "arm,vexpress-shutdown",
+		.data = (void *)FUNC_SHUTDOWN
+	}, {
+		.compatible = "arm,vexpress-reboot",
+		.data = (void *)FUNC_REBOOT
+	},
+	{}
+};
+
+static int vexpress_reset_probe(struct platform_device *pdev)
+{
+	enum vexpress_reset_func func;
+	const struct of_device_id *match =
+			of_match_device(vexpress_reset_of_match, &pdev->dev);
+
+	if (match)
+		func = (enum vexpress_reset_func)match->data;
+	else
+		func = pdev->id_entry->driver_data;
+
+	switch (func) {
+	case FUNC_SHUTDOWN:
+		vexpress_power_off_device = &pdev->dev;
+		break;
+	case FUNC_RESET:
+		if (!vexpress_restart_device)
+			vexpress_restart_device = &pdev->dev;
+		device_create_file(&pdev->dev, &dev_attr_active);
+		break;
+	case FUNC_REBOOT:
+		vexpress_restart_device = &pdev->dev;
+		device_create_file(&pdev->dev, &dev_attr_active);
+		break;
+	};
+
+	return 0;
+}
+
+static const struct platform_device_id vexpress_reset_id_table[] = {
+	{ .name = "vexpress-reset", .driver_data = FUNC_RESET, },
+	{ .name = "vexpress-shutdown", .driver_data = FUNC_SHUTDOWN, },
+	{ .name = "vexpress-reboot", .driver_data = FUNC_REBOOT, },
+	{}
+};
+
+static struct platform_driver vexpress_reset_driver = {
+	.probe = vexpress_reset_probe,
+	.driver = {
+		.name = "vexpress-reset",
+		.of_match_table = vexpress_reset_of_match,
+	},
+	.id_table = vexpress_reset_id_table,
+};
+
+static int __init vexpress_reset_init(void)
+{
+	return platform_driver_register(&vexpress_reset_driver);
+}
+device_initcall(vexpress_reset_init);
diff --git a/include/linux/vexpress.h b/include/linux/vexpress.h
index 8ed285c..8423083 100644
--- a/include/linux/vexpress.h
+++ b/include/linux/vexpress.h
@@ -86,4 +86,7 @@ unsigned __vexpress_get_site(struct device *dev, struct device_node *node);
 void vexpress_sysreg_early_init(void __iomem *base);
 void vexpress_sysreg_of_early_init(void);
 
+void vexpress_power_off(void);
+void vexpress_restart(char str, const char *cmd);
+
 #endif
-- 
1.7.9.5

  parent reply	other threads:[~2012-09-18 14:17 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-18 14:17 [PATCH v2 00/13] Versatile Express infrastructure Pawel Moll
2012-09-18 14:17 ` [PATCH v2 01/13] input: ambakmi: (Un)prepare clocks when (dis)enabling Pawel Moll
2012-09-18 14:17 ` [PATCH v2 02/13] video: Versatile Express display output driver Pawel Moll
2012-09-18 14:17 ` [PATCH v2 03/13] hwmon: Versatile Express hwmon driver Pawel Moll
2012-09-18 15:24   ` Guenter Roeck
2012-09-18 15:45     ` Jean Delvare
2012-09-18 20:59       ` Guenter Roeck
2012-09-19 17:04     ` Pawel Moll
2012-09-20  2:03       ` Guenter Roeck
2012-09-18 14:17 ` [PATCH v2 04/13] regulators: Versatile Express regulator driver Pawel Moll
2012-09-18 15:02   ` Mark Brown
2012-09-18 15:44     ` Pawel Moll
2012-09-18 16:09       ` Mark Brown
2012-09-18 17:03         ` Pawel Moll
2012-09-19  2:21           ` Mark Brown
2012-09-19 16:58             ` Pawel Moll
2012-09-20 13:01               ` Mark Brown
2012-09-20 17:34                 ` Pawel Moll
2012-09-20 18:15                   ` Mark Brown
2012-09-18 14:17 ` [PATCH v2 05/13] clk: Versatile Express clock generators ("osc") driver Pawel Moll
2012-10-29 17:44   ` Mike Turquette
2012-09-18 14:17 ` [PATCH v2 06/13] clk: Common clocks implementation for Versatile Express Pawel Moll
2012-09-18 14:17 ` [PATCH v2 07/13] misc: Versatile Express config infrastructure Pawel Moll
2012-09-19 13:08   ` Arnd Bergmann
2012-09-20 12:06     ` Pawel Moll
2012-09-20 12:36       ` Arnd Bergmann
2012-09-20 12:37         ` Pawel Moll
2012-09-18 14:17 ` [PATCH v2 08/13] mfd: Versatile Express system registers driver Pawel Moll
2012-09-18 15:24   ` Arnd Bergmann
2012-09-19 10:53     ` Pawel Moll
2012-09-19 11:17       ` Arnd Bergmann
2012-09-19 11:45         ` Pawel Moll
2012-09-18 14:17 ` Pawel Moll [this message]
2012-09-18 14:17 ` [PATCH v2 10/13] ARM: vexpress: Add config bus components and clocks to DTs Pawel Moll
2012-09-18 14:17 ` [PATCH v2 11/13] ARM: vexpress: Start using new Versatile Express infrastructure Pawel Moll
2012-09-18 14:17 ` [PATCH v2 12/13] ARM: vexpress: Remove motherboard dependencies in the DTS files Pawel Moll
2012-09-18 14:17 ` [PATCH v2 13/13] ARM: vexpress: Make the DEBUG_LL UART detection more specific Pawel Moll

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=1347977875-16855-10-git-send-email-pawel.moll@arm.com \
    --to=pawel.moll@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).