mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/2] watchdog: new driver for Armada XP
Date: Thu, 30 Mar 2017 20:46:36 +0200	[thread overview]
Message-ID: <20170330184636.22846-3-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20170330184636.22846-1-u.kleine-koenig@pengutronix.de>

This SoC uses a variant of the IP that is also used on most other
Marvell SoCs. For now it only supports Armada XP but the naming is
already chosen such that adding support for further SoCs doesn't result
in much renaming.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/watchdog/Kconfig     |   6 +++
 drivers/watchdog/Makefile    |   1 +
 drivers/watchdog/orion_wdt.c | 123 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)
 create mode 100644 drivers/watchdog/orion_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 63fb1a8c5701..83b6528a5f5f 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -46,4 +46,10 @@ config WATCHDOG_OMAP
 	help
 	  Add support for watchdog on the TI OMAP SoC.
 
+config WATCHDOG_ORION
+	bool "Watchdog for Armada XP"
+	depends on ARCH_ARMADA_XP
+	help
+	  Add support for watchdog on the Marvall Armada XP
+
 endif
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 5fca4c368c40..a3b26675ce96 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_WATCHDOG_MXS28) += im28wd.o
 obj-$(CONFIG_WATCHDOG_DW) += dw_wdt.o
 obj-$(CONFIG_WATCHDOG_JZ4740) += jz4740.o
 obj-$(CONFIG_WATCHDOG_IMX_RESET_SOURCE) += imxwd.o
+obj-$(CONFIG_WATCHDOG_ORION) += orion_wdt.o
diff --git a/drivers/watchdog/orion_wdt.c b/drivers/watchdog/orion_wdt.c
new file mode 100644
index 000000000000..fcdfcd56f9a9
--- /dev/null
+++ b/drivers/watchdog/orion_wdt.c
@@ -0,0 +1,123 @@
+/*
+ * Watchdog driver for Marvell Armada XP.
+ *
+ * Copyright (C) 2017 Pengutronix, Fridolin Tux <kernel@pengutronix.de>
+ *
+ * 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.
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <init.h>
+#include <io.h>
+#include <malloc.h>
+#include <of.h>
+#include <watchdog.h>
+
+#define CLKRATE 25000000
+
+/* registers relative to timer_base (i.e. first reg property) */
+#define TIMER_CTRL	0x00
+#define TIMER_CTRL_WD_TIMER_25MHZ_EN	BIT(10)
+#define TIMER_CTRL_WD_TIMER_EN		BIT(8)
+
+#define TIMER_STATUS	0x04
+#define TIMER_STATUS_WD_EXPIRED		BIT(31)
+
+#define TIMER_WD_TIMER	0x34
+
+/* registers relative to rstout_base (i.e. second reg property) */
+#define WD_RSTOUTn_MASK	0x00
+#define WD_RSTOUTn_MASK_GLOBAL_WD	BIT(8)
+
+struct orion_wdt_ddata {
+	struct watchdog wd;
+	void __iomem *timer_base;
+	void __iomem *rstout_base;
+};
+
+static int armada_xp_set_timeout(struct watchdog *wd, unsigned timeout)
+{
+	struct orion_wdt_ddata *ddata =
+		container_of(wd, struct orion_wdt_ddata, wd);
+	u32 ctrl;
+
+	if (0xffffffff / CLKRATE < timeout)
+		return -EINVAL;
+
+	ctrl = readl(ddata->timer_base + TIMER_CTRL);
+
+	if (timeout == 0) {
+		/* disable timer */
+		ctrl &= ~TIMER_CTRL_WD_TIMER_EN;
+		writel(ctrl, ddata->timer_base + TIMER_CTRL);
+
+		return 0;
+	}
+
+	/* setup duration */
+	writel(CLKRATE * timeout, ddata->timer_base + TIMER_WD_TIMER);
+
+	/* clear expiration status */
+	writel(readl(ddata->timer_base + TIMER_STATUS) & ~TIMER_STATUS_WD_EXPIRED,
+	       ddata->timer_base + TIMER_STATUS);
+
+	/* assert reset on expiration */
+	writel(WD_RSTOUTn_MASK_GLOBAL_WD, ddata->rstout_base + WD_RSTOUTn_MASK);
+
+	/* enable */
+	ctrl |= TIMER_CTRL_WD_TIMER_25MHZ_EN | TIMER_CTRL_WD_TIMER_EN;
+	writel(ctrl, ddata->timer_base + TIMER_CTRL);
+
+	return 0;
+}
+
+static int orion_wdt_probe(struct device_d *dev)
+{
+	struct orion_wdt_ddata* ddata;
+	struct resource *res_timer, *res_rstout;
+
+	ddata = xzalloc(sizeof(*ddata));
+
+	ddata->wd.set_timeout = armada_xp_set_timeout;
+	ddata->wd.name = "orion_wdt";
+	ddata->wd.dev = dev;
+
+	res_timer = dev_request_mem_resource(dev, 0);
+	if (IS_ERR(res_timer)) {
+		dev_err(dev, "could not get timer memory region\n");
+		return PTR_ERR(res_timer);
+	}
+	ddata->timer_base = IOMEM(res_timer->start);
+
+	res_rstout = dev_request_mem_resource(dev, 1);
+	if (IS_ERR(res_rstout)) {
+		dev_err(dev, "could not get rstout memory region\n");
+		release_region(res_timer);
+
+		return PTR_ERR(res_rstout);
+	}
+	ddata->rstout_base = IOMEM(res_rstout->start);
+
+	return watchdog_register(&ddata->wd);
+}
+
+static const struct of_device_id orion_wdt_of_match[] = {
+	{
+		.compatible = "marvell,armada-xp-wdt",
+	}, { /* sentinel */ }
+};
+
+static struct driver_d orion_wdt_driver = {
+	.probe = orion_wdt_probe,
+	.name = "orion_wdt",
+	.of_compatible = DRV_OF_COMPAT(orion_wdt_of_match),
+};
+device_platform_driver(orion_wdt_driver);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2017-03-30 18:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-30 18:46 [PATCH 0/2] Watchdog support for mvebu " Uwe Kleine-König
2017-03-30 18:46 ` [PATCH 1/2] clocksource: mvebu: don't request the used iomem resource Uwe Kleine-König
2017-03-30 18:46 ` Uwe Kleine-König [this message]
2017-03-30 18:54   ` [PATCH 2/2] watchdog: new driver for Armada XP Uwe Kleine-König
2017-03-31  6:09     ` Sascha Hauer

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=20170330184636.22846-3-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=barebox@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