mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v1 1/3] watchdog: add ar9344-wdt driver
@ 2017-11-21 20:04 Oleksij Rempel
  2017-11-21 20:04 ` [PATCH v1 2/3] MIPS: dts: ar9344: add watchdog node Oleksij Rempel
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Oleksij Rempel @ 2017-11-21 20:04 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

this driver was developed and tested on QCA AR9344 WiSoC
but it may work on most know Atheros/QCA WiSoCs.

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
---
 drivers/watchdog/Kconfig      |   6 ++
 drivers/watchdog/Makefile     |   1 +
 drivers/watchdog/ar9344_wdt.c | 136 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+)
 create mode 100644 drivers/watchdog/ar9344_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 83b6528..1f04c7f 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -10,6 +10,12 @@ menuconfig WATCHDOG
 
 if WATCHDOG
 
+config WATCHDOG_AR9344
+	bool "QCA AR9344"
+	depends on SOC_QCA_AR9344
+	help
+	  Add support for watchdog on the QCA AR9344 SoC.
+
 config WATCHDOG_DAVINCI
 	bool "TI Davinci"
 	depends on ARCH_DAVINCI
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index a3b2667..c607f75 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_WATCHDOG) += wd_core.o
+obj-$(CONFIG_WATCHDOG_AR9344) += ar9344_wdt.o
 obj-$(CONFIG_WATCHDOG_DAVINCI) += davinci_wdt.o
 obj-$(CONFIG_WATCHDOG_OMAP) += omap_wdt.o
 obj-$(CONFIG_WATCHDOG_MXS28) += im28wd.o
diff --git a/drivers/watchdog/ar9344_wdt.c b/drivers/watchdog/ar9344_wdt.c
new file mode 100644
index 0000000..1f44604
--- /dev/null
+++ b/drivers/watchdog/ar9344_wdt.c
@@ -0,0 +1,136 @@
+/*
+ *  AR9344 Watchdog driver
+ *
+ *  Copyright (C) 2017 Oleksij Rempel <linux@rempel-privat.de>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under  the terms of the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <init.h>
+#include <io.h>
+#include <linux/clk.h>
+#include <of.h>
+#include <reset_source.h>
+#include <watchdog.h>
+
+#define AR9344_WD_REG_CTRL		0x00
+#define AR9344_WD_CTRL_LAST_RESET	BIT(31)
+#define AR9344_WD_CTRL_ACTION_MASK	3
+#define AR9344_WD_CTRL_ACTION_NONE	0	/* no action */
+#define AR9344_WD_CTRL_ACTION_GPI	1	/* general purpose interrupt */
+#define AR9344_WD_CTRL_ACTION_NMI	2	/* NMI */
+#define AR9344_WD_CTRL_ACTION_FCR	3	/* full chip reset */
+
+#define AR9344_WD_REG_TIMER		0x04
+
+#define to_ar9344_wd(h) container_of(h, struct ar9344_wd, wd)
+
+struct ar9344_wd {
+	struct watchdog		wd;
+	void __iomem		*base;
+	struct clk		*clk;
+	struct device_d		*dev;
+};
+
+static int ar9344_watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
+{
+	struct ar9344_wd *priv = (struct ar9344_wd *)to_ar9344_wd(wd);
+	u32 val, ctrl, rate, max_timout;
+
+	rate = clk_get_rate(priv->clk);
+	max_timout = U32_MAX / rate;
+
+	if (timeout > max_timout) {
+		dev_err(priv->dev, "timeout value out of range: %d > %d\n",
+			timeout, max_timout);
+		return -EINVAL;
+	}
+
+	if (timeout) {
+		ctrl = AR9344_WD_CTRL_ACTION_FCR;
+		val = timeout * rate;
+	} else {
+		ctrl = AR9344_WD_CTRL_ACTION_NONE;
+		val = U32_MAX;
+	}
+
+	dev_dbg(priv->dev, "%s: %d, timer:%x, ctrl: %x \n", __func__,
+		timeout, val, ctrl);
+
+	iowrite32be(val, priv->base + AR9344_WD_REG_TIMER);
+	iowrite32be(ctrl, priv->base + AR9344_WD_REG_CTRL);
+
+	return 0;
+}
+
+static void ar9344_watchdog_detect_reset_source(struct ar9344_wd *priv)
+{
+	u32 val = readw(priv->base + AR9344_WD_REG_CTRL);
+
+	if (val & AR9344_WD_CTRL_LAST_RESET)
+		reset_source_set(RESET_WDG);
+
+	/* else keep the default 'unknown' state */
+}
+
+static int ar9344_wdt_probe(struct device_d *dev)
+{
+	struct resource *iores;
+	struct ar9344_wd *priv;
+	int ret;
+
+	priv = xzalloc(sizeof(struct ar9344_wd));
+	iores = dev_request_mem_resource(dev, 0);
+	if (IS_ERR(iores)) {
+		dev_err(dev, "could not get memory region\n");
+		return PTR_ERR(iores);
+	}
+
+	priv->base = IOMEM(iores->start);
+	priv->wd.set_timeout = ar9344_watchdog_set_timeout;
+	priv->wd.dev = dev;
+	priv->dev = dev;
+
+	dev->priv = priv;
+
+	ar9344_watchdog_detect_reset_source(priv);
+
+	priv->clk = clk_get(dev, NULL);
+	if (WARN_ON(IS_ERR(priv->clk))) {
+		ret = PTR_ERR(priv->clk);
+		goto on_error;
+	}
+
+	clk_enable(priv->clk);
+
+	ret = watchdog_register(&priv->wd);
+	if (ret)
+		goto on_error;
+
+	return 0;
+
+on_error:
+	free(priv);
+	return ret;
+}
+
+static __maybe_unused struct of_device_id ar9344_wdt_dt_ids[] = {
+	{
+		.compatible = "qca,ar9344-wdt",
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct driver_d ar9344_wdt_driver = {
+	.name   = "ar9344-wdt",
+	.probe  = ar9344_wdt_probe,
+	.of_compatible = DRV_OF_COMPAT(ar9344_wdt_dt_ids),
+};
+device_platform_driver(ar9344_wdt_driver);
-- 
2.7.4


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

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

* [PATCH v1 2/3] MIPS: dts: ar9344: add watchdog node
  2017-11-21 20:04 [PATCH v1 1/3] watchdog: add ar9344-wdt driver Oleksij Rempel
@ 2017-11-21 20:04 ` Oleksij Rempel
  2017-11-21 20:04 ` [PATCH v1 3/3] MIPS: dts: tl_wdr4300: enable " Oleksij Rempel
  2017-11-22  5:52 ` [PATCH v1 1/3] watchdog: add ar9344-wdt driver Sam Ravnborg
  2 siblings, 0 replies; 5+ messages in thread
From: Oleksij Rempel @ 2017-11-21 20:04 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
---
 arch/mips/dts/ar9344.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/mips/dts/ar9344.dtsi b/arch/mips/dts/ar9344.dtsi
index 0a7171b..009ff6f 100644
--- a/arch/mips/dts/ar9344.dtsi
+++ b/arch/mips/dts/ar9344.dtsi
@@ -58,6 +58,13 @@
 				#clock-cells = <1>;
 			};
 
+			wdt0: wdt@18060008 {
+				compatible = "qca,ar9344-wdt";
+				reg = <0x18060008 0x8>;
+				clocks = <&pll ATH79_CLK_CPU>;
+				status = "disabled";
+			};
+
 			spi: spi@1f000000 {
 				compatible = "qca,ar7100-spi", "qca,ar9344-spi";
 				reg = <0x1f000000 0x1c>;
-- 
2.7.4


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

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

* [PATCH v1 3/3] MIPS: dts: tl_wdr4300: enable watchdog node
  2017-11-21 20:04 [PATCH v1 1/3] watchdog: add ar9344-wdt driver Oleksij Rempel
  2017-11-21 20:04 ` [PATCH v1 2/3] MIPS: dts: ar9344: add watchdog node Oleksij Rempel
@ 2017-11-21 20:04 ` Oleksij Rempel
  2017-11-22  5:52 ` [PATCH v1 1/3] watchdog: add ar9344-wdt driver Sam Ravnborg
  2 siblings, 0 replies; 5+ messages in thread
From: Oleksij Rempel @ 2017-11-21 20:04 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
---
 arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts b/arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts
index d16cab0..5216cdc 100644
--- a/arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts
+++ b/arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts
@@ -38,6 +38,10 @@
 	clock-frequency = <40000000>;
 };
 
+&wdt0 {
+	status = "okay";
+};
+
 &spi {
 	num-chipselects = <1>;
 	status = "okay";
-- 
2.7.4


_______________________________________________
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 v1 1/3] watchdog: add ar9344-wdt driver
  2017-11-21 20:04 [PATCH v1 1/3] watchdog: add ar9344-wdt driver Oleksij Rempel
  2017-11-21 20:04 ` [PATCH v1 2/3] MIPS: dts: ar9344: add watchdog node Oleksij Rempel
  2017-11-21 20:04 ` [PATCH v1 3/3] MIPS: dts: tl_wdr4300: enable " Oleksij Rempel
@ 2017-11-22  5:52 ` Sam Ravnborg
  2017-11-22 15:25   ` Oleksij Rempel
  2 siblings, 1 reply; 5+ messages in thread
From: Sam Ravnborg @ 2017-11-22  5:52 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox

Hi Oleksij.

nitpick mode..

	Sam

On Tue, Nov 21, 2017 at 09:04:33PM +0100, Oleksij Rempel wrote:
> this driver was developed and tested on QCA AR9344 WiSoC
  ^ Capital T
> but it may work on most know Atheros/QCA WiSoCs.
                          ^known

> 
> Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
> ---
>  drivers/watchdog/Kconfig      |   6 ++
>  drivers/watchdog/Makefile     |   1 +
>  drivers/watchdog/ar9344_wdt.c | 136 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 143 insertions(+)
>  create mode 100644 drivers/watchdog/ar9344_wdt.c
> 
> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> index 83b6528..1f04c7f 100644
> --- a/drivers/watchdog/Kconfig
> +++ b/drivers/watchdog/Kconfig
> @@ -10,6 +10,12 @@ menuconfig WATCHDOG
>  
>  if WATCHDOG
>  
> +config WATCHDOG_AR9344
> +	bool "QCA AR9344"
> +	depends on SOC_QCA_AR9344
> +	help
> +	  Add support for watchdog on the QCA AR9344 SoC.
> +
>  config WATCHDOG_DAVINCI
>  	bool "TI Davinci"
>  	depends on ARCH_DAVINCI
> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> index a3b2667..c607f75 100644
> --- a/drivers/watchdog/Makefile
> +++ b/drivers/watchdog/Makefile
> @@ -1,4 +1,5 @@
>  obj-$(CONFIG_WATCHDOG) += wd_core.o
> +obj-$(CONFIG_WATCHDOG_AR9344) += ar9344_wdt.o
>  obj-$(CONFIG_WATCHDOG_DAVINCI) += davinci_wdt.o
>  obj-$(CONFIG_WATCHDOG_OMAP) += omap_wdt.o
>  obj-$(CONFIG_WATCHDOG_MXS28) += im28wd.o
> diff --git a/drivers/watchdog/ar9344_wdt.c b/drivers/watchdog/ar9344_wdt.c
> new file mode 100644
> index 0000000..1f44604
> --- /dev/null
> +++ b/drivers/watchdog/ar9344_wdt.c
> @@ -0,0 +1,136 @@
> +/*
> + *  AR9344 Watchdog driver
> + *
> + *  Copyright (C) 2017 Oleksij Rempel <linux@rempel-privat.de>
> + *
> + *  This program is free software; you can redistribute it and/or modify it
> + *  under  the terms of the GNU General  Public License as published by the
> + *  Free Software Foundation;  either version 2 of the License, or (at your
> + *  option) any later version.
> + *
> + */
> +
> +#include <common.h>
> +#include <errno.h>
> +#include <init.h>
> +#include <io.h>
> +#include <linux/clk.h>
> +#include <of.h>
> +#include <reset_source.h>
> +#include <watchdog.h>
> +
> +#define AR9344_WD_REG_CTRL		0x00
> +#define AR9344_WD_CTRL_LAST_RESET	BIT(31)
> +#define AR9344_WD_CTRL_ACTION_MASK	3
> +#define AR9344_WD_CTRL_ACTION_NONE	0	/* no action */
> +#define AR9344_WD_CTRL_ACTION_GPI	1	/* general purpose interrupt */
> +#define AR9344_WD_CTRL_ACTION_NMI	2	/* NMI */
> +#define AR9344_WD_CTRL_ACTION_FCR	3	/* full chip reset */
> +
> +#define AR9344_WD_REG_TIMER		0x04
> +
> +#define to_ar9344_wd(h) container_of(h, struct ar9344_wd, wd)
> +
> +struct ar9344_wd {
> +	struct watchdog		wd;
> +	void __iomem		*base;
> +	struct clk		*clk;
> +	struct device_d		*dev;
> +};
> +
> +static int ar9344_watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
> +{
> +	struct ar9344_wd *priv = (struct ar9344_wd *)to_ar9344_wd(wd);
Is this cast necessary when container_of is used?
I did not think, but I think not.

> +	u32 val, ctrl, rate, max_timout;
> +
> +	rate = clk_get_rate(priv->clk);
> +	max_timout = U32_MAX / rate;
> +
> +	if (timeout > max_timout) {
> +		dev_err(priv->dev, "timeout value out of range: %d > %d\n",
> +			timeout, max_timout);
> +		return -EINVAL;
> +	}
> +
> +	if (timeout) {
> +		ctrl = AR9344_WD_CTRL_ACTION_FCR;
> +		val = timeout * rate;
> +	} else {
> +		ctrl = AR9344_WD_CTRL_ACTION_NONE;
> +		val = U32_MAX;
> +	}
> +
> +	dev_dbg(priv->dev, "%s: %d, timer:%x, ctrl: %x \n", __func__,
> +		timeout, val, ctrl);
> +
> +	iowrite32be(val, priv->base + AR9344_WD_REG_TIMER);
> +	iowrite32be(ctrl, priv->base + AR9344_WD_REG_CTRL);
> +
> +	return 0;
> +}
> +
> +static void ar9344_watchdog_detect_reset_source(struct ar9344_wd *priv)
> +{
> +	u32 val = readw(priv->base + AR9344_WD_REG_CTRL);
> +
> +	if (val & AR9344_WD_CTRL_LAST_RESET)
> +		reset_source_set(RESET_WDG);
> +
> +	/* else keep the default 'unknown' state */
> +}
> +
> +static int ar9344_wdt_probe(struct device_d *dev)
> +{
> +	struct resource *iores;
> +	struct ar9344_wd *priv;
> +	int ret;
> +
> +	priv = xzalloc(sizeof(struct ar9344_wd));
> +	iores = dev_request_mem_resource(dev, 0);
> +	if (IS_ERR(iores)) {
> +		dev_err(dev, "could not get memory region\n");
> +		return PTR_ERR(iores);
priv is not released is this error situation.

> +	}
> +
> +	priv->base = IOMEM(iores->start);
> +	priv->wd.set_timeout = ar9344_watchdog_set_timeout;
> +	priv->wd.dev = dev;
> +	priv->dev = dev;
> +
> +	dev->priv = priv;
> +
> +	ar9344_watchdog_detect_reset_source(priv);
> +
> +	priv->clk = clk_get(dev, NULL);
> +	if (WARN_ON(IS_ERR(priv->clk))) {
dev_err - to log what is wrong?

> +		ret = PTR_ERR(priv->clk);
> +		goto on_error;
> +	}
> +
> +	clk_enable(priv->clk);
> +
> +	ret = watchdog_register(&priv->wd);
> +	if (ret)
> +		goto on_error;
> +
> +	return 0;
> +
> +on_error:
> +	free(priv);
> +	return ret;
> +}
> +
> +static __maybe_unused struct of_device_id ar9344_wdt_dt_ids[] = {
> +	{
> +		.compatible = "qca,ar9344-wdt",
> +	}, {
> +		/* sentinel */
> +	}
> +};
> +
> +static struct driver_d ar9344_wdt_driver = {
> +	.name   = "ar9344-wdt",
> +	.probe  = ar9344_wdt_probe,
> +	.of_compatible = DRV_OF_COMPAT(ar9344_wdt_dt_ids),
> +};
> +device_platform_driver(ar9344_wdt_driver);
> -- 
> 2.7.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
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 v1 1/3] watchdog: add ar9344-wdt driver
  2017-11-22  5:52 ` [PATCH v1 1/3] watchdog: add ar9344-wdt driver Sam Ravnborg
@ 2017-11-22 15:25   ` Oleksij Rempel
  0 siblings, 0 replies; 5+ messages in thread
From: Oleksij Rempel @ 2017-11-22 15:25 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: barebox


[-- Attachment #1.1.1: Type: text/plain, Size: 6089 bytes --]

Hi Sam,

thank you for review. Next version is on the way.

Am 22.11.2017 um 06:52 schrieb Sam Ravnborg:
> Hi Oleksij.
> 
> nitpick mode..
> 
> 	Sam
> 
> On Tue, Nov 21, 2017 at 09:04:33PM +0100, Oleksij Rempel wrote:
>> this driver was developed and tested on QCA AR9344 WiSoC
>   ^ Capital T
>> but it may work on most know Atheros/QCA WiSoCs.
>                           ^known
> 
>>
>> Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
>> ---
>>  drivers/watchdog/Kconfig      |   6 ++
>>  drivers/watchdog/Makefile     |   1 +
>>  drivers/watchdog/ar9344_wdt.c | 136 ++++++++++++++++++++++++++++++++++++++++++
>>  3 files changed, 143 insertions(+)
>>  create mode 100644 drivers/watchdog/ar9344_wdt.c
>>
>> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
>> index 83b6528..1f04c7f 100644
>> --- a/drivers/watchdog/Kconfig
>> +++ b/drivers/watchdog/Kconfig
>> @@ -10,6 +10,12 @@ menuconfig WATCHDOG
>>  
>>  if WATCHDOG
>>  
>> +config WATCHDOG_AR9344
>> +	bool "QCA AR9344"
>> +	depends on SOC_QCA_AR9344
>> +	help
>> +	  Add support for watchdog on the QCA AR9344 SoC.
>> +
>>  config WATCHDOG_DAVINCI
>>  	bool "TI Davinci"
>>  	depends on ARCH_DAVINCI
>> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
>> index a3b2667..c607f75 100644
>> --- a/drivers/watchdog/Makefile
>> +++ b/drivers/watchdog/Makefile
>> @@ -1,4 +1,5 @@
>>  obj-$(CONFIG_WATCHDOG) += wd_core.o
>> +obj-$(CONFIG_WATCHDOG_AR9344) += ar9344_wdt.o
>>  obj-$(CONFIG_WATCHDOG_DAVINCI) += davinci_wdt.o
>>  obj-$(CONFIG_WATCHDOG_OMAP) += omap_wdt.o
>>  obj-$(CONFIG_WATCHDOG_MXS28) += im28wd.o
>> diff --git a/drivers/watchdog/ar9344_wdt.c b/drivers/watchdog/ar9344_wdt.c
>> new file mode 100644
>> index 0000000..1f44604
>> --- /dev/null
>> +++ b/drivers/watchdog/ar9344_wdt.c
>> @@ -0,0 +1,136 @@
>> +/*
>> + *  AR9344 Watchdog driver
>> + *
>> + *  Copyright (C) 2017 Oleksij Rempel <linux@rempel-privat.de>
>> + *
>> + *  This program is free software; you can redistribute it and/or modify it
>> + *  under  the terms of the GNU General  Public License as published by the
>> + *  Free Software Foundation;  either version 2 of the License, or (at your
>> + *  option) any later version.
>> + *
>> + */
>> +
>> +#include <common.h>
>> +#include <errno.h>
>> +#include <init.h>
>> +#include <io.h>
>> +#include <linux/clk.h>
>> +#include <of.h>
>> +#include <reset_source.h>
>> +#include <watchdog.h>
>> +
>> +#define AR9344_WD_REG_CTRL		0x00
>> +#define AR9344_WD_CTRL_LAST_RESET	BIT(31)
>> +#define AR9344_WD_CTRL_ACTION_MASK	3
>> +#define AR9344_WD_CTRL_ACTION_NONE	0	/* no action */
>> +#define AR9344_WD_CTRL_ACTION_GPI	1	/* general purpose interrupt */
>> +#define AR9344_WD_CTRL_ACTION_NMI	2	/* NMI */
>> +#define AR9344_WD_CTRL_ACTION_FCR	3	/* full chip reset */
>> +
>> +#define AR9344_WD_REG_TIMER		0x04
>> +
>> +#define to_ar9344_wd(h) container_of(h, struct ar9344_wd, wd)
>> +
>> +struct ar9344_wd {
>> +	struct watchdog		wd;
>> +	void __iomem		*base;
>> +	struct clk		*clk;
>> +	struct device_d		*dev;
>> +};
>> +
>> +static int ar9344_watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
>> +{
>> +	struct ar9344_wd *priv = (struct ar9344_wd *)to_ar9344_wd(wd);
> Is this cast necessary when container_of is used?
> I did not think, but I think not.
> 
>> +	u32 val, ctrl, rate, max_timout;
>> +
>> +	rate = clk_get_rate(priv->clk);
>> +	max_timout = U32_MAX / rate;
>> +
>> +	if (timeout > max_timout) {
>> +		dev_err(priv->dev, "timeout value out of range: %d > %d\n",
>> +			timeout, max_timout);
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (timeout) {
>> +		ctrl = AR9344_WD_CTRL_ACTION_FCR;
>> +		val = timeout * rate;
>> +	} else {
>> +		ctrl = AR9344_WD_CTRL_ACTION_NONE;
>> +		val = U32_MAX;
>> +	}
>> +
>> +	dev_dbg(priv->dev, "%s: %d, timer:%x, ctrl: %x \n", __func__,
>> +		timeout, val, ctrl);
>> +
>> +	iowrite32be(val, priv->base + AR9344_WD_REG_TIMER);
>> +	iowrite32be(ctrl, priv->base + AR9344_WD_REG_CTRL);
>> +
>> +	return 0;
>> +}
>> +
>> +static void ar9344_watchdog_detect_reset_source(struct ar9344_wd *priv)
>> +{
>> +	u32 val = readw(priv->base + AR9344_WD_REG_CTRL);
>> +
>> +	if (val & AR9344_WD_CTRL_LAST_RESET)
>> +		reset_source_set(RESET_WDG);
>> +
>> +	/* else keep the default 'unknown' state */
>> +}
>> +
>> +static int ar9344_wdt_probe(struct device_d *dev)
>> +{
>> +	struct resource *iores;
>> +	struct ar9344_wd *priv;
>> +	int ret;
>> +
>> +	priv = xzalloc(sizeof(struct ar9344_wd));
>> +	iores = dev_request_mem_resource(dev, 0);
>> +	if (IS_ERR(iores)) {
>> +		dev_err(dev, "could not get memory region\n");
>> +		return PTR_ERR(iores);
> priv is not released is this error situation.
> 
>> +	}
>> +
>> +	priv->base = IOMEM(iores->start);
>> +	priv->wd.set_timeout = ar9344_watchdog_set_timeout;
>> +	priv->wd.dev = dev;
>> +	priv->dev = dev;
>> +
>> +	dev->priv = priv;
>> +
>> +	ar9344_watchdog_detect_reset_source(priv);
>> +
>> +	priv->clk = clk_get(dev, NULL);
>> +	if (WARN_ON(IS_ERR(priv->clk))) {
> dev_err - to log what is wrong?
> 
>> +		ret = PTR_ERR(priv->clk);
>> +		goto on_error;
>> +	}
>> +
>> +	clk_enable(priv->clk);
>> +
>> +	ret = watchdog_register(&priv->wd);
>> +	if (ret)
>> +		goto on_error;
>> +
>> +	return 0;
>> +
>> +on_error:
>> +	free(priv);
>> +	return ret;
>> +}
>> +
>> +static __maybe_unused struct of_device_id ar9344_wdt_dt_ids[] = {
>> +	{
>> +		.compatible = "qca,ar9344-wdt",
>> +	}, {
>> +		/* sentinel */
>> +	}
>> +};
>> +
>> +static struct driver_d ar9344_wdt_driver = {
>> +	.name   = "ar9344-wdt",
>> +	.probe  = ar9344_wdt_probe,
>> +	.of_compatible = DRV_OF_COMPAT(ar9344_wdt_dt_ids),
>> +};
>> +device_platform_driver(ar9344_wdt_driver);
>> -- 
>> 2.7.4
>>
>>
>> _______________________________________________
>> barebox mailing list
>> barebox@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/barebox


-- 
Regards,
Oleksij


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
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-11-22 15:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-21 20:04 [PATCH v1 1/3] watchdog: add ar9344-wdt driver Oleksij Rempel
2017-11-21 20:04 ` [PATCH v1 2/3] MIPS: dts: ar9344: add watchdog node Oleksij Rempel
2017-11-21 20:04 ` [PATCH v1 3/3] MIPS: dts: tl_wdr4300: enable " Oleksij Rempel
2017-11-22  5:52 ` [PATCH v1 1/3] watchdog: add ar9344-wdt driver Sam Ravnborg
2017-11-22 15:25   ` Oleksij Rempel

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