mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/2] Watchdog support for mvebu Armada XP
@ 2017-03-30 18:46 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 ` [PATCH 2/2] watchdog: new driver for Armada XP Uwe Kleine-König
  0 siblings, 2 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2017-03-30 18:46 UTC (permalink / raw)
  To: barebox

Hello,

this series adds a simple watchdog driver for mvebu Armada XP. One
not-so-nice thing here is that the iomem range is already taken
by the timer code because the register range of the two dt nodes
overlap. To work around that the first patch is necessary.

Best regards
Uwe

Uwe Kleine-König (2):
  clocksource: mvebu: don't request the used iomem resource
  watchdog: new driver for Armada XP

 drivers/clocksource/mvebu.c  |   2 +-
 drivers/watchdog/Kconfig     |   6 +++
 drivers/watchdog/Makefile    |   1 +
 drivers/watchdog/orion_wdt.c | 123 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 131 insertions(+), 1 deletion(-)
 create mode 100644 drivers/watchdog/orion_wdt.c

-- 
2.11.0


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

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

* [PATCH 1/2] clocksource: mvebu: don't request the used iomem resource
  2017-03-30 18:46 [PATCH 0/2] Watchdog support for mvebu Armada XP Uwe Kleine-König
@ 2017-03-30 18:46 ` Uwe Kleine-König
  2017-03-30 18:46 ` [PATCH 2/2] watchdog: new driver for Armada XP Uwe Kleine-König
  1 sibling, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2017-03-30 18:46 UTC (permalink / raw)
  To: barebox

The register ranges of the device nodes timer@20300 and watchdog@20300
overlap, so it is impossible that both devices properly use
request_iomem_region (e.g. by using dev_request_mem_resource). In Linux
only the watchdog driver is registered in /proc/iomem, do the same for
barebox.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/clocksource/mvebu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clocksource/mvebu.c b/drivers/clocksource/mvebu.c
index cf80571263d9..59bbc4be22a4 100644
--- a/drivers/clocksource/mvebu.c
+++ b/drivers/clocksource/mvebu.c
@@ -60,7 +60,7 @@ static int mvebu_timer_probe(struct device_d *dev)
 	struct clk *clk;
 	u32 rate, div, val;
 
-	iores = dev_request_mem_resource(dev, 0);
+	iores = dev_get_resource(dev, IORESOURCE_MEM, 0);
 	if (IS_ERR(iores))
 		return PTR_ERR(iores);
 	timer_base = IOMEM(iores->start);
-- 
2.11.0


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

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

* [PATCH 2/2] watchdog: new driver for Armada XP
  2017-03-30 18:46 [PATCH 0/2] Watchdog support for mvebu Armada XP 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
  2017-03-30 18:54   ` Uwe Kleine-König
  1 sibling, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2017-03-30 18:46 UTC (permalink / raw)
  To: barebox

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

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

* Re: [PATCH 2/2] watchdog: new driver for Armada XP
  2017-03-30 18:46 ` [PATCH 2/2] watchdog: new driver for Armada XP Uwe Kleine-König
@ 2017-03-30 18:54   ` Uwe Kleine-König
  2017-03-31  6:09     ` Sascha Hauer
  0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2017-03-30 18:54 UTC (permalink / raw)
  To: barebox

Hello,

On Thu, Mar 30, 2017 at 08:46:36PM +0200, Uwe Kleine-König wrote:
> 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>

huh, copied from the template without adoption. Can you please
s/Fridolin Tux/Uwe Kleine-König/ here? Or should I resend?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

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

* Re: [PATCH 2/2] watchdog: new driver for Armada XP
  2017-03-30 18:54   ` Uwe Kleine-König
@ 2017-03-31  6:09     ` Sascha Hauer
  0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2017-03-31  6:09 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: barebox

On Thu, Mar 30, 2017 at 08:54:03PM +0200, Uwe Kleine-König wrote:
> Hello,
> 
> On Thu, Mar 30, 2017 at 08:46:36PM +0200, Uwe Kleine-König wrote:
> > 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>
> 
> huh, copied from the template without adoption. Can you please
> s/Fridolin Tux/Uwe Kleine-König/ here? Or should I resend?

Fixed that while applying. Thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

end of thread, other threads:[~2017-03-31  6:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-30 18:46 [PATCH 0/2] Watchdog support for mvebu Armada XP 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 ` [PATCH 2/2] watchdog: new driver for Armada XP Uwe Kleine-König
2017-03-30 18:54   ` Uwe Kleine-König
2017-03-31  6:09     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox