mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] wdog: imx-wd: Introduce ops struct for imx21/imx1
@ 2015-04-02 15:36 Markus Pargmann
  2015-04-02 15:36 ` [PATCH 2/2] wdog: imx-wd: Disable watchdog powerdown counter Markus Pargmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Markus Pargmann @ 2015-04-02 15:36 UTC (permalink / raw)
  To: barebox

Replace the set_timeout function in the device platform data by an ops
struct which stores a set_timeout and init function.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/watchdog/imxwd.c | 54 +++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 42 insertions(+), 12 deletions(-)

diff --git a/drivers/watchdog/imxwd.c b/drivers/watchdog/imxwd.c
index 31c3d0d85353..42edfe00d2bc 100644
--- a/drivers/watchdog/imxwd.c
+++ b/drivers/watchdog/imxwd.c
@@ -21,11 +21,18 @@
 #include <watchdog.h>
 #include <reset_source.h>
 
+struct imx_wd;
+
+struct imx_wd_ops {
+	int (*set_timeout)(struct imx_wd *, int);
+	int (*init)(struct imx_wd *);
+};
+
 struct imx_wd {
 	struct watchdog wd;
 	void __iomem *base;
 	struct device_d *dev;
-	int (*set_timeout)(struct imx_wd *, unsigned);
+	const struct imx_wd_ops *ops;
 };
 
 #define to_imx_wd(h) container_of(h, struct imx_wd, wd)
@@ -110,7 +117,7 @@ static int imx_watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
 {
 	struct imx_wd *priv = (struct imx_wd *)to_imx_wd(wd);
 
-	return priv->set_timeout(priv, timeout);
+	return priv->ops->set_timeout(priv, timeout);
 }
 
 static struct imx_wd *reset_wd;
@@ -118,7 +125,7 @@ static struct imx_wd *reset_wd;
 void __noreturn reset_cpu(unsigned long addr)
 {
 	if (reset_wd)
-		reset_wd->set_timeout(reset_wd, -1);
+		reset_wd->ops->set_timeout(reset_wd, -1);
 
 	mdelay(1000);
 
@@ -147,13 +154,20 @@ static void imx_watchdog_detect_reset_source(struct imx_wd *priv)
 	/* else keep the default 'unknown' state */
 }
 
+static int imx21_wd_init(struct imx_wd *priv)
+{
+	imx_watchdog_detect_reset_source(priv);
+
+	return 0;
+}
+
 static int imx_wd_probe(struct device_d *dev)
 {
 	struct imx_wd *priv;
-	void *fn;
+	void *ops;
 	int ret;
 
-	ret = dev_get_drvdata(dev, (unsigned long *)&fn);
+	ret = dev_get_drvdata(dev, (unsigned long *)&ops);
 	if (ret)
 		return ret;
 
@@ -163,7 +177,7 @@ static int imx_wd_probe(struct device_d *dev)
 		dev_err(dev, "could not get memory region\n");
 		return -ENODEV;
 	}
-	priv->set_timeout = fn;
+	priv->ops = ops;
 	priv->wd.set_timeout = imx_watchdog_set_timeout;
 	priv->dev = dev;
 
@@ -176,13 +190,20 @@ static int imx_wd_probe(struct device_d *dev)
 			goto on_error;
 	}
 
-	if (fn != imx1_watchdog_set_timeout)
-		imx_watchdog_detect_reset_source(priv);
+	if (priv->ops->init) {
+		ret = priv->ops->init(priv);
+		if (ret) {
+			dev_err(dev, "Failed to init watchdog device %d\n", ret);
+			goto error_unregister;
+		}
+	}
 
 	dev->priv = priv;
 
 	return 0;
 
+error_unregister:
+	watchdog_deregister(&priv->wd);
 on_error:
 	if (reset_wd && reset_wd != priv)
 		free(priv);
@@ -200,13 +221,22 @@ static void imx_wd_remove(struct device_d *dev)
 		free(priv);
 }
 
+static const struct imx_wd_ops imx21_wd_ops = {
+	.set_timeout = imx21_watchdog_set_timeout,
+	.init = imx21_wd_init,
+};
+
+static const struct imx_wd_ops imx1_wd_ops = {
+	.set_timeout = imx1_watchdog_set_timeout,
+};
+
 static __maybe_unused struct of_device_id imx_wdt_dt_ids[] = {
 	{
 		.compatible = "fsl,imx1-wdt",
-		.data = (unsigned long)&imx1_watchdog_set_timeout,
+		.data = (unsigned long)&imx1_wd_ops,
 	}, {
 		.compatible = "fsl,imx21-wdt",
-		.data = (unsigned long)&imx21_watchdog_set_timeout,
+		.data = (unsigned long)&imx21_wd_ops,
 	}, {
 		/* sentinel */
 	}
@@ -215,10 +245,10 @@ static __maybe_unused struct of_device_id imx_wdt_dt_ids[] = {
 static struct platform_device_id imx_wdt_ids[] = {
 	{
 		.name = "imx1-wdt",
-		.driver_data = (unsigned long)&imx1_watchdog_set_timeout,
+		.driver_data = (unsigned long)&imx1_wd_ops,
 	}, {
 		.name = "imx21-wdt",
-		.driver_data = (unsigned long)&imx21_watchdog_set_timeout,
+		.driver_data = (unsigned long)&imx21_wd_ops,
 	}, {
 		/* sentinel */
 	},
-- 
2.1.4


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

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

* [PATCH 2/2] wdog: imx-wd: Disable watchdog powerdown counter
  2015-04-02 15:36 [PATCH 1/2] wdog: imx-wd: Introduce ops struct for imx21/imx1 Markus Pargmann
@ 2015-04-02 15:36 ` Markus Pargmann
  2015-04-03  6:16 ` [PATCH 1/2] wdog: imx-wd: Introduce ops struct for imx21/imx1 Sascha Hauer
  2015-04-03 13:51 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Pargmann @ 2015-04-02 15:36 UTC (permalink / raw)
  To: barebox

Disable the watchdog powerdown counter at start. Otherwise this may
trigger a reset or poweroff over the WDOG_B line to a PMIC. This counter
is set to 16 seconds after poweron.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/watchdog/imxwd.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/watchdog/imxwd.c b/drivers/watchdog/imxwd.c
index 42edfe00d2bc..3479d7b02da7 100644
--- a/drivers/watchdog/imxwd.c
+++ b/drivers/watchdog/imxwd.c
@@ -46,6 +46,7 @@ struct imx_wd {
 #define IMX21_WDOG_WCR	0x00 /* Watchdog Control Register */
 #define IMX21_WDOG_WSR	0x02 /* Watchdog Service Register */
 #define IMX21_WDOG_WSTR	0x04 /* Watchdog Status Register  */
+#define IMX21_WDOG_WMCR	0x08 /* Misc Register */
 #define IMX21_WDOG_WCR_WDE	(1 << 2)
 #define IMX21_WDOG_WCR_SRS	(1 << 4)
 #define IMX21_WDOG_WCR_WDA	(1 << 5)
@@ -158,6 +159,11 @@ static int imx21_wd_init(struct imx_wd *priv)
 {
 	imx_watchdog_detect_reset_source(priv);
 
+	/*
+	 * Disable watchdog powerdown counter
+	 */
+	writew(0x0, priv->base + IMX21_WDOG_WMCR);
+
 	return 0;
 }
 
-- 
2.1.4


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

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

* Re: [PATCH 1/2] wdog: imx-wd: Introduce ops struct for imx21/imx1
  2015-04-02 15:36 [PATCH 1/2] wdog: imx-wd: Introduce ops struct for imx21/imx1 Markus Pargmann
  2015-04-02 15:36 ` [PATCH 2/2] wdog: imx-wd: Disable watchdog powerdown counter Markus Pargmann
@ 2015-04-03  6:16 ` Sascha Hauer
  2015-04-03 13:51 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2015-04-03  6:16 UTC (permalink / raw)
  To: Markus Pargmann; +Cc: barebox

On Thu, Apr 02, 2015 at 05:36:50PM +0200, Markus Pargmann wrote:
> Replace the set_timeout function in the device platform data by an ops
> struct which stores a set_timeout and init function.
> 
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
> ---
>  drivers/watchdog/imxwd.c | 54 +++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 42 insertions(+), 12 deletions(-)

Applied, 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] 4+ messages in thread

* Re: [PATCH 1/2] wdog: imx-wd: Introduce ops struct for imx21/imx1
  2015-04-02 15:36 [PATCH 1/2] wdog: imx-wd: Introduce ops struct for imx21/imx1 Markus Pargmann
  2015-04-02 15:36 ` [PATCH 2/2] wdog: imx-wd: Disable watchdog powerdown counter Markus Pargmann
  2015-04-03  6:16 ` [PATCH 1/2] wdog: imx-wd: Introduce ops struct for imx21/imx1 Sascha Hauer
@ 2015-04-03 13:51 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2015-04-03 13:51 UTC (permalink / raw)
  To: Markus Pargmann; +Cc: barebox

On Thu, Apr 02, 2015 at 05:36:50PM +0200, Markus Pargmann wrote:
> Replace the set_timeout function in the device platform data by an ops
> struct which stores a set_timeout and init function.
> 
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
>  	}
>  
> -	if (fn != imx1_watchdog_set_timeout)
> -		imx_watchdog_detect_reset_source(priv);
> +	if (priv->ops->init) {
> +		ret = priv->ops->init(priv);
> +		if (ret) {
> +			dev_err(dev, "Failed to init watchdog device %d\n", ret);
> +			goto error_unregister;
> +		}
> +	}
>  
>  	dev->priv = priv;
>  
>  	return 0;
>  
> +error_unregister:
> +	watchdog_deregister(&priv->wd);

I had to revert this one because compilation fails with:

imx-iomux-v1.c:(.text.imx_wd_probe+0xb0): undefined reference to `watchdog_deregister'

This happens when watchdog support is disabled. imxwd.c is compiled
anyway because it provides the reset function. Either you have to
provide static inline wrappers or reorder the code so that
watchdog_register is called last and thus you don't have to call
watchdog_deregister().

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] 4+ messages in thread

end of thread, other threads:[~2015-04-03 13:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-02 15:36 [PATCH 1/2] wdog: imx-wd: Introduce ops struct for imx21/imx1 Markus Pargmann
2015-04-02 15:36 ` [PATCH 2/2] wdog: imx-wd: Disable watchdog powerdown counter Markus Pargmann
2015-04-03  6:16 ` [PATCH 1/2] wdog: imx-wd: Introduce ops struct for imx21/imx1 Sascha Hauer
2015-04-03 13:51 ` Sascha Hauer

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