]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
dm: watchdog: add BCM6345 watchdog driver
authorÁlvaro Fernández Rojas <noltari@gmail.com>
Tue, 16 May 2017 16:29:09 +0000 (18:29 +0200)
committerDaniel Schwierzeck <daniel.schwierzeck@gmail.com>
Wed, 31 May 2017 12:49:54 +0000 (14:49 +0200)
This driver is a simplified version of linux/drivers/watchdog/bcm63xx_wdt.c

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/watchdog/Kconfig
drivers/watchdog/Makefile
drivers/watchdog/bcm6345_wdt.c [new file with mode: 0644]

index 22a7c4f80180d804d6c69e8645de6705fef257f9..b911233db3d8cb8a0e4c90c1f8c48a9e9fb3de35 100644 (file)
@@ -54,4 +54,12 @@ config WDT_ASPEED
          It currently does not support Boot Flash Addressing Mode Detection or
          Second Boot.
 
+config WDT_BCM6345
+       bool "BCM6345 watchdog timer support"
+       depends on WDT && ARCH_BMIPS
+       help
+         Select this to enable watchdog timer for BCM6345 SoCs.
+         The watchdog timer is stopped when initialized.
+         It performs full SoC reset.
+
 endmenu
index 8378601b33124cb6e5d6236be95c12ee6dbc6550..4b19e4ccf68c9aabbfc2f23cf198ed0b49f4bdd8 100644 (file)
@@ -18,4 +18,5 @@ obj-$(CONFIG_ULP_WATCHDOG) += ulp_wdog.o
 obj-$(CONFIG_WDT) += wdt-uclass.o
 obj-$(CONFIG_WDT_SANDBOX) += sandbox_wdt.o
 obj-$(CONFIG_WDT_ASPEED) += ast_wdt.o
+obj-$(CONFIG_WDT_BCM6345) += bcm6345_wdt.o
 obj-$(CONFIG_BCM2835_WDT)       += bcm2835_wdt.o
diff --git a/drivers/watchdog/bcm6345_wdt.c b/drivers/watchdog/bcm6345_wdt.c
new file mode 100644 (file)
index 0000000..c6b02ec
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
+ *
+ * Derived from linux/drivers/watchdog/bcm63xx_wdt.c:
+ *     Copyright (C) 2007 Miguel Gaio <miguel.gaio@efixo.com>
+ *     Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <wdt.h>
+#include <asm/io.h>
+
+/* WDT Value register */
+#define WDT_VAL_REG            0x0
+#define WDT_VAL_MIN            0x00000002
+#define WDT_VAL_MAX            0xfffffffe
+
+/* WDT Control register */
+#define WDT_CTL_REG            0x4
+#define WDT_CTL_START1_MASK    0x0000ff00
+#define WDT_CTL_START2_MASK    0x000000ff
+#define WDT_CTL_STOP1_MASK     0x0000ee00
+#define WDT_CTL_STOP2_MASK     0x000000ee
+
+struct bcm6345_wdt_priv {
+       void __iomem *regs;
+};
+
+static int bcm6345_wdt_reset(struct udevice *dev)
+{
+       struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
+
+       writel_be(WDT_CTL_START1_MASK, priv->regs + WDT_CTL_REG);
+       writel_be(WDT_CTL_START2_MASK, priv->regs + WDT_CTL_REG);
+
+       return 0;
+}
+
+static int bcm6345_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
+{
+       struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
+
+       if (timeout < WDT_VAL_MIN) {
+               debug("watchdog won't fire with less than 2 ticks\n");
+               timeout = WDT_VAL_MIN;
+       } else if (timeout > WDT_VAL_MAX) {
+               debug("maximum watchdog timeout exceeded\n");
+               timeout = WDT_VAL_MAX;
+       }
+
+       writel_be(timeout, priv->regs + WDT_VAL_REG);
+
+       return bcm6345_wdt_reset(dev);
+}
+
+static int bcm6345_wdt_expire_now(struct udevice *dev, ulong flags)
+{
+       return bcm6345_wdt_start(dev, WDT_VAL_MIN, flags);
+}
+
+static int bcm6345_wdt_stop(struct udevice *dev)
+{
+       struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
+
+       writel_be(WDT_CTL_STOP1_MASK, priv->regs + WDT_CTL_REG);
+       writel_be(WDT_CTL_STOP2_MASK, priv->regs + WDT_CTL_REG);
+
+       return 0;
+}
+
+static const struct wdt_ops bcm6345_wdt_ops = {
+       .expire_now = bcm6345_wdt_expire_now,
+       .reset = bcm6345_wdt_reset,
+       .start = bcm6345_wdt_start,
+       .stop = bcm6345_wdt_stop,
+};
+
+static const struct udevice_id bcm6345_wdt_ids[] = {
+       { .compatible = "brcm,bcm6345-wdt" },
+       { /* sentinel */ }
+};
+
+static int bcm6345_wdt_probe(struct udevice *dev)
+{
+       struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
+       fdt_addr_t addr;
+       fdt_size_t size;
+
+       addr = dev_get_addr_size_index(dev, 0, &size);
+       if (addr == FDT_ADDR_T_NONE)
+               return -EINVAL;
+
+       priv->regs = ioremap(addr, size);
+
+       bcm6345_wdt_stop(dev);
+
+       return 0;
+}
+
+U_BOOT_DRIVER(wdt_bcm6345) = {
+       .name = "wdt_bcm6345",
+       .id = UCLASS_WDT,
+       .of_match = bcm6345_wdt_ids,
+       .ops = &bcm6345_wdt_ops,
+       .priv_auto_alloc_size = sizeof(struct bcm6345_wdt_priv),
+       .probe = bcm6345_wdt_probe,
+};