All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jagan Teki <jagan-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>
To: Kever Yang <kever.yang-TNX95d0MmH7DzftRWevZcw@public.gmane.org>,
	Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	Philipp Tomsich
	<philipp.tomsich-SN7IsUiht6C/RdPyistoZJqQE7yCjDx5@public.gmane.org>
Cc: linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	Chin Liang See <clsee-EIB2kfCEclfQT0dZR+AlfA@public.gmane.org>,
	u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.org,
	Jagan Teki
	<jagan-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>,
	Andy Shevchenko
	<andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
	linux-amarula-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org,
	Akash Gajjar <akash-oRp2ZoJdM/RWk0Htik3J/w@public.gmane.org>
Subject: [PATCH 08/15] wdt: dw: Add driver-model support
Date: Mon, 29 Jul 2019 13:17:04 +0530	[thread overview]
Message-ID: <20190729074711.16988-9-jagan@amarulasolutions.com> (raw)
In-Reply-To: <20190729074711.16988-1-jagan-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>

Add driver-model code for designware watchdog.

Cc: Chin Liang See <clsee-EIB2kfCEclfQT0dZR+AlfA@public.gmane.org>
Cc: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Signed-off-by: Jagan Teki <jagan-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>
---
 drivers/watchdog/designware_wdt.c | 114 +++++++++++++++++++++++++++++-
 1 file changed, 113 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c
index 2979fda44e..4efbb25f86 100644
--- a/drivers/watchdog/designware_wdt.c
+++ b/drivers/watchdog/designware_wdt.c
@@ -4,7 +4,6 @@
  */
 
 #include <common.h>
-#include <watchdog.h>
 #include <asm/io.h>
 #include <asm/utils.h>
 
@@ -16,6 +15,117 @@
 #define DW_WDT_CR_RMOD_OFFSET	0x01
 #define DW_WDT_CRR_RESTART_VAL	0x76
 
+#ifdef CONFIG_WDT
+
+#include <dm.h>
+#include <wdt.h>
+#include <clk.h>
+
+struct dw_wdt {
+	void __iomem *regs;
+	unsigned long clk_rate;
+};
+
+static inline int dw_wdt_is_enabled(struct dw_wdt *dw)
+{
+	return readl(dw->regs + DW_WDT_CR) & DW_WDT_CR_RMOD_OFFSET;
+}
+
+/*
+ * Set the watchdog time interval.
+ * Counter is 32 bit.
+ */
+static int dw_wdt_set_timeout(struct dw_wdt *dw, unsigned int timeout)
+{
+	signed int i;
+
+	/* calculate the timeout range value */
+	i = (log_2_n_round_up(timeout * dw->clk_rate)) - 16;
+	if (i > 15)
+		i = 15;
+	if (i < 0)
+		i = 0;
+
+	writel((i | (i << 4)), dw->regs + DW_WDT_TORR);
+
+	return 0;
+}
+
+static void dw_wdt_enable(struct dw_wdt *dw)
+{
+	u32 val = readl(dw->regs + DW_WDT_CR);
+
+	/* Enable watchdog */
+	val |= DW_WDT_CR_RMOD_OFFSET;
+	writel(val, dw->regs + DW_WDT_CR);
+}
+
+static int dw_wdt_reset(struct udevice *dev)
+{
+	struct dw_wdt *dw = dev_get_priv(dev);
+
+	if (dw_wdt_is_enabled(dw))
+		writel(DW_WDT_CRR_RESTART_VAL, dw->regs + DW_WDT_CRR);
+	else
+		dw_wdt_enable(dw);
+
+	return 0;
+}
+
+static int dw_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
+{
+	struct dw_wdt *dw = dev_get_priv(dev);
+
+	dw_wdt_set_timeout(dw, timeout);
+	dw_wdt_enable(dw);
+
+	return 0;
+}
+
+static int dw_wdt_probe(struct udevice *dev)
+{
+	struct dw_wdt *dw = dev_get_priv(dev);
+	struct clk clk;
+	int ret;
+
+	dw->regs = dev_remap_addr(dev);
+	if (!dw->regs)
+		return -EINVAL;
+
+	ret = clk_get_by_index(dev, 0, &clk);
+	if (!ret)
+		dw->clk_rate = clk_get_rate(&clk);
+	else
+		return -EINVAL;
+
+	dw_wdt_reset(dev);
+
+	return 0;
+}
+
+static const struct wdt_ops dw_wdt_ops = {
+	.reset = dw_wdt_reset,
+	.start = dw_wdt_start,
+};
+
+static const struct udevice_id dw_wdt_ids[] = {
+	{ .compatible = "snps,dw-wdt" },
+	{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(dw_wdt) = {
+	.name = "dw_wdt",
+	.id = UCLASS_WDT,
+	.of_match = dw_wdt_ids,
+	.ops = &dw_wdt_ops,
+	.priv_auto_alloc_size = sizeof(struct dw_wdt),
+	.probe = dw_wdt_probe,
+};
+
+#else
+
+#include <watchdog.h>
+
 /*
  * Set the watchdog time interval.
  * Counter is 32 bit.
@@ -70,3 +180,5 @@ void hw_watchdog_init(void)
 	hw_watchdog_reset();
 }
 #endif
+
+#endif /* CONFIG_WDT */
-- 
2.18.0.321.gffc6fa0e3

WARNING: multiple messages have this Message-ID (diff)
From: Jagan Teki <jagan@amarulasolutions.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 08/15] wdt: dw: Add driver-model support
Date: Mon, 29 Jul 2019 13:17:04 +0530	[thread overview]
Message-ID: <20190729074711.16988-9-jagan@amarulasolutions.com> (raw)
In-Reply-To: <20190729074711.16988-1-jagan@amarulasolutions.com>

Add driver-model code for designware watchdog.

Cc: Chin Liang See <clsee@altera.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
---
 drivers/watchdog/designware_wdt.c | 114 +++++++++++++++++++++++++++++-
 1 file changed, 113 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c
index 2979fda44e..4efbb25f86 100644
--- a/drivers/watchdog/designware_wdt.c
+++ b/drivers/watchdog/designware_wdt.c
@@ -4,7 +4,6 @@
  */
 
 #include <common.h>
-#include <watchdog.h>
 #include <asm/io.h>
 #include <asm/utils.h>
 
@@ -16,6 +15,117 @@
 #define DW_WDT_CR_RMOD_OFFSET	0x01
 #define DW_WDT_CRR_RESTART_VAL	0x76
 
+#ifdef CONFIG_WDT
+
+#include <dm.h>
+#include <wdt.h>
+#include <clk.h>
+
+struct dw_wdt {
+	void __iomem *regs;
+	unsigned long clk_rate;
+};
+
+static inline int dw_wdt_is_enabled(struct dw_wdt *dw)
+{
+	return readl(dw->regs + DW_WDT_CR) & DW_WDT_CR_RMOD_OFFSET;
+}
+
+/*
+ * Set the watchdog time interval.
+ * Counter is 32 bit.
+ */
+static int dw_wdt_set_timeout(struct dw_wdt *dw, unsigned int timeout)
+{
+	signed int i;
+
+	/* calculate the timeout range value */
+	i = (log_2_n_round_up(timeout * dw->clk_rate)) - 16;
+	if (i > 15)
+		i = 15;
+	if (i < 0)
+		i = 0;
+
+	writel((i | (i << 4)), dw->regs + DW_WDT_TORR);
+
+	return 0;
+}
+
+static void dw_wdt_enable(struct dw_wdt *dw)
+{
+	u32 val = readl(dw->regs + DW_WDT_CR);
+
+	/* Enable watchdog */
+	val |= DW_WDT_CR_RMOD_OFFSET;
+	writel(val, dw->regs + DW_WDT_CR);
+}
+
+static int dw_wdt_reset(struct udevice *dev)
+{
+	struct dw_wdt *dw = dev_get_priv(dev);
+
+	if (dw_wdt_is_enabled(dw))
+		writel(DW_WDT_CRR_RESTART_VAL, dw->regs + DW_WDT_CRR);
+	else
+		dw_wdt_enable(dw);
+
+	return 0;
+}
+
+static int dw_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
+{
+	struct dw_wdt *dw = dev_get_priv(dev);
+
+	dw_wdt_set_timeout(dw, timeout);
+	dw_wdt_enable(dw);
+
+	return 0;
+}
+
+static int dw_wdt_probe(struct udevice *dev)
+{
+	struct dw_wdt *dw = dev_get_priv(dev);
+	struct clk clk;
+	int ret;
+
+	dw->regs = dev_remap_addr(dev);
+	if (!dw->regs)
+		return -EINVAL;
+
+	ret = clk_get_by_index(dev, 0, &clk);
+	if (!ret)
+		dw->clk_rate = clk_get_rate(&clk);
+	else
+		return -EINVAL;
+
+	dw_wdt_reset(dev);
+
+	return 0;
+}
+
+static const struct wdt_ops dw_wdt_ops = {
+	.reset = dw_wdt_reset,
+	.start = dw_wdt_start,
+};
+
+static const struct udevice_id dw_wdt_ids[] = {
+	{ .compatible = "snps,dw-wdt" },
+	{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(dw_wdt) = {
+	.name = "dw_wdt",
+	.id = UCLASS_WDT,
+	.of_match = dw_wdt_ids,
+	.ops = &dw_wdt_ops,
+	.priv_auto_alloc_size = sizeof(struct dw_wdt),
+	.probe = dw_wdt_probe,
+};
+
+#else
+
+#include <watchdog.h>
+
 /*
  * Set the watchdog time interval.
  * Counter is 32 bit.
@@ -70,3 +180,5 @@ void hw_watchdog_init(void)
 	hw_watchdog_reset();
 }
 #endif
+
+#endif /* CONFIG_WDT */
-- 
2.18.0.321.gffc6fa0e3

  parent reply	other threads:[~2019-07-29  7:47 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-29  7:46 [PATCH 00/15] rk3399: Add redundant boot support Jagan Teki
2019-07-29  7:46 ` [U-Boot] " Jagan Teki
     [not found] ` <20190729074711.16988-1-jagan-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>
2019-07-29  7:46   ` [PATCH 01/15] arm: rockchip: Add common cru.h Jagan Teki
2019-07-29  7:46     ` [U-Boot] " Jagan Teki
     [not found]     ` <20190729074711.16988-2-jagan-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>
2019-08-05 12:25       ` Kever Yang
2019-08-05 12:25         ` [U-Boot] " Kever Yang
2019-08-25 17:25         ` Jagan Teki
2019-08-25 17:25           ` [U-Boot] " Jagan Teki
2019-07-29  7:46   ` [PATCH 02/15] rockchip: Add cpu-info Jagan Teki
2019-07-29  7:46     ` [U-Boot] " Jagan Teki
     [not found]     ` <20190729074711.16988-3-jagan-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>
2019-08-05 12:27       ` Kever Yang
2019-08-05 12:27         ` [U-Boot] " Kever Yang
2019-07-29  7:46   ` [PATCH 03/15] rockchip: rk3288: Print reset reason Jagan Teki
2019-07-29  7:46     ` [U-Boot] " Jagan Teki
     [not found]     ` <20190729074711.16988-4-jagan-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>
2019-07-29  7:57       ` Matthias Urlichs
2019-08-05 12:30       ` Kever Yang
2019-08-05 12:30         ` [U-Boot] " Kever Yang
     [not found]         ` <98408a3c-84bd-d54b-1b3a-49901c85ba3c-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2019-08-14  9:40           ` Jagan Teki
2019-08-14  9:40             ` [U-Boot] " Jagan Teki
2019-08-14 10:43             ` Wadim Egorov
2019-08-14 10:43               ` [U-Boot] " Wadim Egorov
2019-08-14 10:46               ` Michael Nazzareno Trimarchi
2019-08-14 10:46                 ` [U-Boot] " Michael Nazzareno Trimarchi
2019-07-29  7:47   ` [PATCH 04/15] rockchip: Add common " Jagan Teki
2019-07-29  7:47     ` [U-Boot] " Jagan Teki
2019-07-29  7:47   ` [PATCH 05/15] rockchip: rk3288/rk3399: Enable DISPLAY_CPUINFO Jagan Teki
2019-07-29  7:47     ` [U-Boot] " Jagan Teki
2019-08-05 12:35     ` Kever Yang
2019-08-05 12:35       ` [U-Boot] " Kever Yang
2019-07-29  7:47   ` [PATCH 06/15] wdt: designware: Simplify is_enabled function Jagan Teki
2019-07-29  7:47     ` [U-Boot] " Jagan Teki
2019-07-29  7:47   ` [PATCH 07/15] wdt: designware: Simplify enable function Jagan Teki
2019-07-29  7:47     ` [U-Boot] " Jagan Teki
2019-07-29  7:47   ` Jagan Teki [this message]
2019-07-29  7:47     ` [U-Boot] [PATCH 08/15] wdt: dw: Add driver-model support Jagan Teki
     [not found]     ` <20190729074711.16988-9-jagan-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>
2019-07-29  9:09       ` Andy Shevchenko
2019-07-29  9:09         ` Andy Shevchenko
2019-07-29  7:47   ` [PATCH 09/15] wdt: dw: Rename to dw_wdt.c Jagan Teki
2019-07-29  7:47     ` [U-Boot] " Jagan Teki
2019-08-05 12:40     ` Kever Yang
2019-08-05 12:40       ` [U-Boot] " Kever Yang
     [not found]       ` <e7507f4e-de8d-e61c-5538-0a3cc203ceba-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2019-08-14  9:44         ` Jagan Teki
2019-08-14  9:44           ` [U-Boot] " Jagan Teki
2019-07-29  7:47   ` [PATCH 10/15] rockchip: dts: rk3399: Add u-boot, dm-pre-reloc for watchdog Jagan Teki
2019-07-29  7:47     ` [U-Boot] " Jagan Teki
2019-07-29  7:47   ` [PATCH 11/15] wdt: Kconfig: Add WDT_DW entry Jagan Teki
2019-07-29  7:47     ` [U-Boot] " Jagan Teki
2019-07-29  7:47   ` [PATCH 12/15] include: rk3399: Disable watchdog in TPL Jagan Teki
2019-07-29  7:47     ` [U-Boot] " Jagan Teki
     [not found]     ` <20190729074711.16988-13-jagan-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>
2019-08-05 12:43       ` Kever Yang
2019-08-05 12:43         ` [U-Boot] " Kever Yang
2019-08-25 20:14         ` Jagan Teki
2019-08-25 20:14           ` [U-Boot] " Jagan Teki
2019-08-26  1:34           ` Kever Yang
2019-08-26  1:34             ` [U-Boot] " Kever Yang
2019-07-29  7:47   ` [DO NOT MERGE] [PATCH 13/15] rk3399: rockpro64: Enable watchdog Jagan Teki
2019-07-29  7:47     ` [U-Boot] " Jagan Teki
2019-07-29  7:47   ` [PATCH 14/15] rockchip: rk3399: Add bootcount support Jagan Teki
2019-07-29  7:47     ` [U-Boot] " Jagan Teki
2019-08-12 12:16     ` Kever Yang
2019-08-12 12:16       ` [U-Boot] " Kever Yang
2019-08-13  1:02       ` [PATCH 14/15] rockchip: rk3399: Add bootcount support【请注意,邮件由u-boot-bounces@lists.denx.de代发】 Kever Yang
2019-08-13  1:02         ` [U-Boot] " Kever Yang
2019-07-29  7:47   ` [DO NOT MERGE] [PATCH 15/15] rk3399: rockpro64: Enable bootcount Jagan Teki
2019-07-29  7:47     ` [U-Boot] " Jagan Teki
2019-08-05 12:18 ` [PATCH 00/15] rk3399: Add redundant boot support Kever Yang
2019-08-05 12:18   ` [U-Boot] " Kever Yang

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=20190729074711.16988-9-jagan@amarulasolutions.com \
    --to=jagan-dyjbcgdgk7pe9whmmfpqlfatqe2ktcn/@public.gmane.org \
    --cc=akash-oRp2ZoJdM/RWk0Htik3J/w@public.gmane.org \
    --cc=andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=clsee-EIB2kfCEclfQT0dZR+AlfA@public.gmane.org \
    --cc=kever.yang-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
    --cc=linux-amarula-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org \
    --cc=linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=philipp.tomsich-SN7IsUiht6C/RdPyistoZJqQE7yCjDx5@public.gmane.org \
    --cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.