mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 06/15] watchdog: imx: Add register accessor functions
Date: Wed, 13 Mar 2019 10:41:53 +0100	[thread overview]
Message-ID: <20190313094202.14901-7-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20190313094202.14901-1-s.hauer@pengutronix.de>

In preparation of adding big endian support in the next step.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/watchdog/imxwd.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/watchdog/imxwd.c b/drivers/watchdog/imxwd.c
index 8dba662392..e2c3b9f96e 100644
--- a/drivers/watchdog/imxwd.c
+++ b/drivers/watchdog/imxwd.c
@@ -66,6 +66,16 @@ struct imx_wd {
 /* valid for i.MX27, i.MX31, always '0' on i.MX25, i.MX35, i.MX51 */
 #define WSTR_COLDSTART	(1 << 4)
 
+static void imxwd_write(struct imx_wd *priv, int reg, uint16_t val)
+{
+	writew(val, priv->base + reg);
+}
+
+static uint16_t imxwd_read(struct imx_wd *priv, int reg)
+{
+	return readw(priv->base + reg);
+}
+
 static int imx1_watchdog_set_timeout(struct imx_wd *priv, unsigned timeout)
 {
 	u16 val;
@@ -73,18 +83,18 @@ static int imx1_watchdog_set_timeout(struct imx_wd *priv, unsigned timeout)
 	dev_dbg(priv->dev, "%s: %d\n", __func__, timeout);
 
 	if (!timeout) {
-		writew(IMX1_WDOG_WCR_WHALT, priv->base + IMX1_WDOG_WCR);
+		imxwd_write(priv, IMX1_WDOG_WCR, IMX1_WDOG_WCR_WHALT);
 		return 0;
 	}
 
 	val = (timeout * 2 - 1) << 8;
 
-	writew(val, priv->base + IMX1_WDOG_WCR);
-	writew(IMX1_WDOG_WCR_WDE | val, priv->base + IMX1_WDOG_WCR);
+	imxwd_write(priv, IMX1_WDOG_WCR, val);
+	imxwd_write(priv, IMX1_WDOG_WCR, IMX1_WDOG_WCR_WDE | val);
 
 	/* Write Service Sequence */
-	writew(0x5555, priv->base + IMX1_WDOG_WSR);
-	writew(0xaaaa, priv->base + IMX1_WDOG_WSR);
+	imxwd_write(priv, IMX1_WDOG_WSR, 0x5555);
+	imxwd_write(priv, IMX1_WDOG_WSR, 0xaaaa);
 
 	return 0;
 }
@@ -113,13 +123,13 @@ static int imx21_watchdog_set_timeout(struct imx_wd *priv, unsigned timeout)
 	 * set time and some write once bits first prior enabling the
 	 * watchdog according to the datasheet
 	 */
-	writew(val, priv->base + IMX21_WDOG_WCR);
+	imxwd_write(priv, IMX21_WDOG_WCR, val);
 
-	writew(IMX21_WDOG_WCR_WDE | val, priv->base + IMX21_WDOG_WCR);
+	imxwd_write(priv, IMX21_WDOG_WCR, IMX21_WDOG_WCR_WDE | val);
 
 	/* Write Service Sequence */
-	writew(0x5555, priv->base + IMX21_WDOG_WSR);
-	writew(0xaaaa, priv->base + IMX21_WDOG_WSR);
+	imxwd_write(priv, IMX21_WDOG_WSR, 0x5555);
+	imxwd_write(priv, IMX21_WDOG_WSR, 0xaaaa);
 
 	return 0;
 }
@@ -134,11 +144,11 @@ static void imx21_soc_reset(struct imx_wd *priv)
 	else
 		val |= IMX21_WDOG_WCR_WDA; /* do not assert ext-reset */
 
-	writew(val, priv->base + IMX21_WDOG_WCR);
+	imxwd_write(priv, IMX21_WDOG_WCR, val);
 
 	/* Two additional writes due to errata ERR004346 */
-	writew(val, priv->base + IMX21_WDOG_WCR);
-	writew(val, priv->base + IMX21_WDOG_WCR);
+	imxwd_write(priv, IMX21_WDOG_WCR, val);
+	imxwd_write(priv, IMX21_WDOG_WCR, val);
 }
 
 static int imx_watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
@@ -161,7 +171,7 @@ static void __noreturn imxwd_force_soc_reset(struct restart_handler *rst)
 
 static void imx_watchdog_detect_reset_source(struct imx_wd *priv)
 {
-	u16 val = readw(priv->base + IMX21_WDOG_WSTR);
+	u16 val = imxwd_read(priv, IMX21_WDOG_WSTR);
 	int priority = RESET_SOURCE_DEFAULT_PRIORITY;
 
 	if (reset_source_get() == RESET_WDG)
@@ -192,7 +202,7 @@ static int imx21_wd_init(struct imx_wd *priv)
 	/*
 	 * Disable watchdog powerdown counter
 	 */
-	writew(0x0, priv->base + IMX21_WDOG_WMCR);
+	imxwd_write(priv, IMX21_WDOG_WMCR, 0x0);
 
 	return 0;
 }
-- 
2.20.1


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

  parent reply	other threads:[~2019-03-13  9:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-13  9:41 [PATCH 00/15] barebox Layerscape support Sascha Hauer
2019-03-13  9:41 ` [PATCH 01/15] mci: imx-esdhc: Actually enable cache snooping Sascha Hauer
2019-03-13  9:41 ` [PATCH 02/15] Add Freescale QUICC Engine firmware support Sascha Hauer
2019-03-13  9:41 ` [PATCH 03/15] net: Add Freescale FMan ethernet support Sascha Hauer
2019-03-13  9:41 ` [PATCH 04/15] ARM: Add arm64 pbl udelay Sascha Hauer
2019-03-19 18:12   ` Andrey Smirnov
2019-03-20  8:16     ` Sascha Hauer
2019-03-22  6:41       ` Andrey Smirnov
2019-03-13  9:41 ` [PATCH 05/15] esdhc-xload: Add support for Layerscape Sascha Hauer
2019-03-13  9:41 ` Sascha Hauer [this message]
2019-03-13  9:41 ` [PATCH 07/15] watchdog: imx: Add big endian register access support Sascha Hauer
2019-03-13  9:41 ` [PATCH 08/15] scripts: Add Layerscape image tool Sascha Hauer
2019-03-13  9:41 ` [PATCH 09/15] i2c: i.MX: Add layerscape support Sascha Hauer
2019-03-13  9:41 ` [PATCH 10/15] ddr: fsl: Add Freescale ddr driver Sascha Hauer
2019-03-13  9:41 ` [PATCH 11/15] ARM: Add basic Layerscape support Sascha Hauer
2019-03-13  9:41 ` [PATCH 12/15] clk: Add Layerscape clk support Sascha Hauer
2019-03-13  9:42 ` [PATCH 13/15] ARM: Layerscape: Add LS1046a RDB board support Sascha Hauer
2019-03-13  9:42 ` [PATCH 14/15] ARM: Layerscape: Add TQ TQMLS1046a " Sascha Hauer
2019-03-13  9:42 ` [PATCH 15/15] ARM: Add layerscape_defconfig Sascha Hauer

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=20190313094202.14901-7-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox