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 03/11] misc: Versatile Express reset driver
Date: Mon,  3 Sep 2012 17:25:23 +0100	[thread overview]
Message-ID: <1346689531-7212-4-git-send-email-pawel.moll@arm.com> (raw)
In-Reply-To: <1346689531-7212-1-git-send-email-pawel.moll@arm.com>

This is a simple vexpress config driver providing platform restart and
power off functions.

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>
---
 drivers/misc/vexpress/Makefile |    1 +
 drivers/misc/vexpress/reset.c  |  110 ++++++++++++++++++++++++++++++++++++++++
 include/linux/vexpress.h       |    4 ++
 3 files changed, 115 insertions(+)
 create mode 100644 drivers/misc/vexpress/reset.c

diff --git a/drivers/misc/vexpress/Makefile b/drivers/misc/vexpress/Makefile
index 5b1e8fc..af11749 100644
--- a/drivers/misc/vexpress/Makefile
+++ b/drivers/misc/vexpress/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_VEXPRESS_CONFIG_BUS) += config_bus.o
+obj-$(CONFIG_VEXPRESS_CONFIG_BUS) += reset.o
diff --git a/drivers/misc/vexpress/reset.c b/drivers/misc/vexpress/reset.c
new file mode 100644
index 0000000..1be7cba
--- /dev/null
+++ b/drivers/misc/vexpress/reset.c
@@ -0,0 +1,110 @@
+/*
+ * 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/stat.h>
+#include <linux/vexpress.h>
+
+static void vexpress_reset_do(struct vexpress_config_device *vecdev,
+		const char *what)
+{
+	int err = -ENOENT;
+
+	if (vecdev) {
+		unsigned long timeout;
+
+		err = vexpress_config_write(vecdev, 0, 0);
+
+		timeout = jiffies + HZ;
+		while (time_before(jiffies, timeout))
+			cpu_relax();
+	}
+
+	dev_emerg(&vecdev->dev, "Unable to %s (%d)\n", what, err);
+}
+
+static struct vexpress_config_device *vexpress_power_off_device;
+
+void vexpress_power_off(void)
+{
+	vexpress_reset_do(vexpress_power_off_device, "power off");
+}
+
+static struct vexpress_config_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 ==
+			to_vexpress_config_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 = to_vexpress_config_device(dev);
+
+	return err ? err : count;
+}
+
+DEVICE_ATTR(active, S_IRUGO | S_IWUSR, vexpress_reset_active_show,
+		vexpress_reset_active_store);
+
+
+static int vexpress_reset_probe(struct vexpress_config_device *vecdev)
+{
+	switch (vecdev->func) {
+	case VEXPRESS_CONFIG_FUNC_SHUTDOWN:
+		vexpress_power_off_device = vecdev;
+		break;
+	case VEXPRESS_CONFIG_FUNC_RESET:
+		if (!vexpress_restart_device)
+			vexpress_restart_device = vecdev;
+		device_create_file(&vecdev->dev, &dev_attr_active);
+		break;
+	case VEXPRESS_CONFIG_FUNC_REBOOT:
+		vexpress_restart_device = vecdev;
+		device_create_file(&vecdev->dev, &dev_attr_active);
+		break;
+	};
+
+	return 0;
+}
+
+static const unsigned vexpress_reset_funcs[] = {
+	VEXPRESS_CONFIG_FUNC_RESET,
+	VEXPRESS_CONFIG_FUNC_SHUTDOWN,
+	VEXPRESS_CONFIG_FUNC_REBOOT,
+	0,
+};
+
+static struct vexpress_config_driver vexpress_reset_driver = {
+	.funcs = vexpress_reset_funcs,
+	.probe = vexpress_reset_probe,
+	.driver.name = "vexpress-reset",
+};
+
+static int __init vexpress_reset_init(void)
+{
+	return vexpress_config_driver_register(&vexpress_reset_driver);
+}
+device_initcall(vexpress_reset_init);
diff --git a/include/linux/vexpress.h b/include/linux/vexpress.h
index f1ed744..7b02341 100644
--- a/include/linux/vexpress.h
+++ b/include/linux/vexpress.h
@@ -117,4 +117,8 @@ int vexpress_config_read(struct vexpress_config_device *vecdev, int offset,
 int vexpress_config_write(struct vexpress_config_device *vecdev, int offset,
 		u32 data);
 
+/* Reset control */
+void vexpress_power_off(void);
+void vexpress_restart(char str, const char *cmd);
+
 #endif
-- 
1.7.9.5

  parent reply	other threads:[~2012-09-03 16:25 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-03 16:25 [PATCH 00/11] Versatile Express infrastructure Pawel Moll
2012-09-03 16:25 ` [PATCH 01/11] input: ambakmi: Add missing clk_[un]prepare() calls Pawel Moll
2012-09-04 13:37   ` Thomas Petazzoni
2012-09-04 13:45     ` Pawel Moll
2012-09-03 16:25 ` [PATCH 02/11] misc: Versatile Express config bus infrastructure Pawel Moll
2012-09-03 21:17   ` Arnd Bergmann
2012-09-04 11:53     ` Pawel Moll
2012-09-04 12:45       ` Arnd Bergmann
2012-09-04 16:41         ` Pawel Moll
2012-09-03 16:25 ` Pawel Moll [this message]
2012-09-03 16:25 ` [PATCH 04/11] misc: Versatile Express display muxer driver Pawel Moll
2012-09-03 21:21   ` Arnd Bergmann
2012-09-04 11:53     ` Pawel Moll
2012-09-03 16:25 ` [PATCH 05/11] clk: Versatile Express clock generators ("osc") driver Pawel Moll
2012-09-10 19:14   ` Mike Turquette
2012-09-11 16:10     ` Pawel Moll
2012-09-11 18:00       ` Linus Walleij
2012-09-12 16:56         ` Pawel Moll
2012-09-11 18:33       ` Mike Turquette
2012-09-03 16:25 ` [PATCH 06/11] clk: Common clocks implementation for Versatile Express Pawel Moll
2012-09-03 21:24   ` Arnd Bergmann
2012-09-04 11:53     ` Pawel Moll
2012-09-04 12:43       ` Linus Walleij
2012-09-04 17:12         ` Ryan Harkin
2012-09-10 20:10   ` Mike Turquette
2012-09-03 16:25 ` [PATCH 07/11] regulators: Versatile Express regulator driver Pawel Moll
2012-09-03 16:25 ` [PATCH 08/11] hwmon: Versatile Express hwmon driver Pawel Moll
2012-09-03 16:25 ` [PATCH 09/11] misc: Versatile Express system registers driver Pawel Moll
2012-09-03 16:25 ` [PATCH 10/11] ARM: vexpress: Add config bus components and clocks to DTs Pawel Moll
2012-09-04 12:58   ` Rob Herring
2012-09-04 13:05     ` Pawel Moll
2012-09-04 14:31       ` Rob Herring
2012-09-04 15:37         ` Pawel Moll
2012-09-04 17:51           ` Rob Herring
2012-09-19  9:44             ` Pawel Moll
2012-09-03 16:25 ` [PATCH 11/11] ARM: vexpress: Start using new Versatile Express infrastructure 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=1346689531-7212-4-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).