diff options
Diffstat (limited to 'drivers/watchdog/imxwd.c')
-rw-r--r-- | drivers/watchdog/imxwd.c | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/drivers/watchdog/imxwd.c b/drivers/watchdog/imxwd.c index 03e116ea20..b920c7234b 100644 --- a/drivers/watchdog/imxwd.c +++ b/drivers/watchdog/imxwd.c @@ -25,7 +25,8 @@ struct imx_wd; struct imx_wd_ops { - int (*set_timeout)(struct imx_wd *, int); + int (*set_timeout)(struct imx_wd *, unsigned); + void (*soc_reset)(struct imx_wd *); int (*init)(struct imx_wd *); }; @@ -35,6 +36,7 @@ struct imx_wd { struct device_d *dev; const struct imx_wd_ops *ops; struct restart_handler restart; + bool ext_reset; }; #define to_imx_wd(h) container_of(h, struct imx_wd, wd) @@ -50,6 +52,7 @@ struct imx_wd { #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_WDT (1 << 3) #define IMX21_WDOG_WCR_SRS (1 << 4) #define IMX21_WDOG_WCR_WDA (1 << 5) @@ -62,7 +65,7 @@ struct imx_wd { /* valid for i.MX27, i.MX31, always '0' on i.MX25, i.MX35, i.MX51 */ #define WSTR_COLDSTART (1 << 4) -static int imx1_watchdog_set_timeout(struct imx_wd *priv, int timeout) +static int imx1_watchdog_set_timeout(struct imx_wd *priv, unsigned timeout) { u16 val; @@ -76,10 +79,7 @@ static int imx1_watchdog_set_timeout(struct imx_wd *priv, int timeout) return 0; } - if (timeout > 0) - val = (timeout * 2 - 1) << 8; - else - val = 0; + val = (timeout * 2 - 1) << 8; writew(val, priv->base + IMX1_WDOG_WCR); writew(IMX1_WDOG_WCR_WDE | val, priv->base + IMX1_WDOG_WCR); @@ -91,25 +91,29 @@ static int imx1_watchdog_set_timeout(struct imx_wd *priv, int timeout) return 0; } -static int imx21_watchdog_set_timeout(struct imx_wd *priv, int timeout) +static void imx1_soc_reset(struct imx_wd *priv) +{ + writew(IMX1_WDOG_WCR_WDE, priv->base + IMX1_WDOG_WCR); +} + +static int imx21_watchdog_set_timeout(struct imx_wd *priv, unsigned timeout) { u16 val; dev_dbg(priv->dev, "%s: %d\n", __func__, timeout); - if (timeout < -1 || timeout > 128) + if (timeout > 128) return -EINVAL; if (timeout == 0) /* bit 2 (WDE) cannot be set to 0 again */ return -ENOSYS; - if (timeout > 0) - val = ((timeout * 2 - 1) << 8) | IMX21_WDOG_WCR_SRS | - IMX21_WDOG_WCR_WDA; - else - val = 0; + val = ((timeout * 2 - 1) << 8) | IMX21_WDOG_WCR_SRS | + IMX21_WDOG_WCR_WDA; + + if (priv->ext_reset) + val |= IMX21_WDOG_WCR_WDT; - writew(val, priv->base + IMX21_WDOG_WCR); writew(IMX21_WDOG_WCR_WDE | val, priv->base + IMX21_WDOG_WCR); /* Write Service Sequence */ @@ -119,6 +123,19 @@ static int imx21_watchdog_set_timeout(struct imx_wd *priv, int timeout) return 0; } +static void imx21_soc_reset(struct imx_wd *priv) +{ + u16 val = 0; + + /* Use internal reset or external - not both */ + if (priv->ext_reset) + val |= IMX21_WDOG_WCR_SRS; /* do not assert int reset */ + else + val |= IMX21_WDOG_WCR_WDA; /* do not assert ext-reset */ + + writew(val, priv->base + IMX21_WDOG_WCR); +} + static int imx_watchdog_set_timeout(struct watchdog *wd, unsigned timeout) { struct imx_wd *priv = (struct imx_wd *)to_imx_wd(wd); @@ -130,7 +147,7 @@ static void __noreturn imxwd_force_soc_reset(struct restart_handler *rst) { struct imx_wd *priv = container_of(rst, struct imx_wd, restart); - priv->ops->set_timeout(priv, -1); + priv->ops->soc_reset(priv); mdelay(1000); @@ -194,6 +211,9 @@ static int imx_wd_probe(struct device_d *dev) priv->wd.dev = dev; priv->dev = dev; + priv->ext_reset = of_property_read_bool(dev->device_node, + "fsl,ext-reset-output"); + if (IS_ENABLED(CONFIG_WATCHDOG_IMX)) { ret = watchdog_register(&priv->wd); if (ret) @@ -227,11 +247,13 @@ on_error: static const struct imx_wd_ops imx21_wd_ops = { .set_timeout = imx21_watchdog_set_timeout, + .soc_reset = imx21_soc_reset, .init = imx21_wd_init, }; static const struct imx_wd_ops imx1_wd_ops = { .set_timeout = imx1_watchdog_set_timeout, + .soc_reset = imx1_soc_reset, }; static __maybe_unused struct of_device_id imx_wdt_dt_ids[] = { |