Re: [PATCH v2 2/2] watchdog: Watchdog driver for Broadcom Set-Top Box
Hi Justin, On Thu, Aug 27, 2015 at 03:53:24PM -0700, Justin Chen wrote: > Watchdog driver for Broadcom 7038 and newer chips. > > Signed-off-by: Justin Chen Almost good. Two little but important details left ... > --- > drivers/watchdog/Kconfig | 8 ++ > drivers/watchdog/Makefile | 1 + > drivers/watchdog/bcm7038_wdt.c | 235 > + > 3 files changed, 244 insertions(+) > create mode 100644 drivers/watchdog/bcm7038_wdt.c > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig > index 241fafd..4fbe8ab 100644 > --- a/drivers/watchdog/Kconfig > +++ b/drivers/watchdog/Kconfig > @@ -1291,6 +1291,14 @@ config BCM_KONA_WDT_DEBUG > > If in doubt, say 'N'. > > +config BCM7038_WDT > + tristate "BCM7038 Watchdog" > + select WATCHDOG_CORE > + help > + Watchdog driver for the built-in hardware in Broadcom 7038 SoCs. > + > + Say 'Y or 'M' here to enable the driver. > + > config IMGPDC_WDT > tristate "Imagination Technologies PDC Watchdog Timer" > depends on HAS_IOMEM > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile > index 59ea9a1..65d4169 100644 > --- a/drivers/watchdog/Makefile > +++ b/drivers/watchdog/Makefile > @@ -66,6 +66,7 @@ obj-$(CONFIG_TEGRA_WATCHDOG) += tegra_wdt.o > obj-$(CONFIG_MESON_WATCHDOG) += meson_wdt.o > obj-$(CONFIG_MEDIATEK_WATCHDOG) += mtk_wdt.o > obj-$(CONFIG_DIGICOLOR_WATCHDOG) += digicolor_wdt.o > +obj-$(CONFIG_BCM7038_WDT) += bcm7038_wdt.o > > # AVR32 Architecture > obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o > diff --git a/drivers/watchdog/bcm7038_wdt.c b/drivers/watchdog/bcm7038_wdt.c > new file mode 100644 > index 000..5e54c1b > --- /dev/null > +++ b/drivers/watchdog/bcm7038_wdt.c > @@ -0,0 +1,235 @@ > +/* > + * Copyright (C) 2015 Broadcom Corporation > + * > + * 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. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define WDT_START_1 0xff00 > +#define WDT_START_2 0x00ff > +#define WDT_STOP_1 0xee00 > +#define WDT_STOP_2 0x00ee > + > +#define WDT_TIMEOUT_REG 0x0 > +#define WDT_CMD_REG 0x4 > + > +#define WDT_MIN_TIMEOUT 1 /* seconds */ > +#define WDT_DEFAULT_TIMEOUT 30 /* seconds */ > +#define WDT_DEFAULT_RATE 2700 > + > +struct bcm7038_watchdog { > + void __iomem*base; > + struct watchdog_device wdd; > + u32 rate; > + struct clk *clk; > +}; > + > +static bool nowayout = WATCHDOG_NOWAYOUT; > + > +static void bcm7038_wdt_set_timeout_reg(struct watchdog_device *wdog) > +{ > + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); > + u32 timeout; > + > + timeout = wdt->rate * wdog->timeout; > + > + writel(timeout, wdt->base + WDT_TIMEOUT_REG); > +} > + > +static int bcm7038_wdt_ping(struct watchdog_device *wdog) > +{ > + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); > + > + writel(WDT_START_1, wdt->base + WDT_CMD_REG); > + writel(WDT_START_2, wdt->base + WDT_CMD_REG); > + > + return 0; > +} > + > +static int bcm7038_wdt_start(struct watchdog_device *wdog) > +{ > + bcm7038_wdt_set_timeout_reg(wdog); > + bcm7038_wdt_ping(wdog); > + > + return 0; > +} > + > +static int bcm7038_wdt_stop(struct watchdog_device *wdog) > +{ > + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); > + > + writel(WDT_STOP_1, wdt->base + WDT_CMD_REG); > + writel(WDT_STOP_2, wdt->base + WDT_CMD_REG); > + > + return 0; > +} > + > +static int bcm7038_wdt_set_timeout(struct watchdog_device *wdog, > +unsigned int t) > +{ > + /* Can't modify timeout value if watchdog timer is running */ > + bcm7038_wdt_stop(wdog); > + wdog->timeout = t; > + bcm7038_wdt_start(wdog); > + > + return 0; > +} > + > +static unsigned int bcm7038_wdt_get_timeleft(struct watchdog_device *wdog) > +{ > + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); > + u32 time_left; > + > + time_left = readl(wdt->base + WDT_CMD_REG); > + > + return time_left / wdt->rate; > +} > + > +static struct watchdog_info bcm7038_wdt_info = { > + .identity = "Broadcom BCM7038 Watchdog Timer", > + .options= WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | > + WDIOF_MAGICCLOSE > +}; > + > +static struct watc
Re: [PATCH v2 2/2] watchdog: Watchdog driver for Broadcom Set-Top Box
Gah, sorry, my email client did something really weird. Sorry for the duplication, please don't reply to those. -- Gregory-- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 2/2] watchdog: Watchdog driver for Broadcom Set-Top Box
Watchdog driver for Broadcom 7038 and newer chips. Signed-off-by: Justin Chen --- drivers/watchdog/Kconfig | 8 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/bcm7038_wdt.c | 235 + 3 files changed, 244 insertions(+) create mode 100644 drivers/watchdog/bcm7038_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 241fafd..4fbe8ab 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -1291,6 +1291,14 @@ config BCM_KONA_WDT_DEBUG If in doubt, say 'N'. +config BCM7038_WDT + tristate "BCM7038 Watchdog" + select WATCHDOG_CORE + help +Watchdog driver for the built-in hardware in Broadcom 7038 SoCs. + +Say 'Y or 'M' here to enable the driver. + config IMGPDC_WDT tristate "Imagination Technologies PDC Watchdog Timer" depends on HAS_IOMEM diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 59ea9a1..65d4169 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_TEGRA_WATCHDOG) += tegra_wdt.o obj-$(CONFIG_MESON_WATCHDOG) += meson_wdt.o obj-$(CONFIG_MEDIATEK_WATCHDOG) += mtk_wdt.o obj-$(CONFIG_DIGICOLOR_WATCHDOG) += digicolor_wdt.o +obj-$(CONFIG_BCM7038_WDT) += bcm7038_wdt.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o diff --git a/drivers/watchdog/bcm7038_wdt.c b/drivers/watchdog/bcm7038_wdt.c new file mode 100644 index 000..5e54c1b --- /dev/null +++ b/drivers/watchdog/bcm7038_wdt.c @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2015 Broadcom Corporation + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define WDT_START_10xff00 +#define WDT_START_20x00ff +#define WDT_STOP_1 0xee00 +#define WDT_STOP_2 0x00ee + +#define WDT_TIMEOUT_REG0x0 +#define WDT_CMD_REG0x4 + +#define WDT_MIN_TIMEOUT1 /* seconds */ +#define WDT_DEFAULT_TIMEOUT30 /* seconds */ +#define WDT_DEFAULT_RATE 2700 + +struct bcm7038_watchdog { + void __iomem*base; + struct watchdog_device wdd; + u32 rate; + struct clk *clk; +}; + +static bool nowayout = WATCHDOG_NOWAYOUT; + +static void bcm7038_wdt_set_timeout_reg(struct watchdog_device *wdog) +{ + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); + u32 timeout; + + timeout = wdt->rate * wdog->timeout; + + writel(timeout, wdt->base + WDT_TIMEOUT_REG); +} + +static int bcm7038_wdt_ping(struct watchdog_device *wdog) +{ + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); + + writel(WDT_START_1, wdt->base + WDT_CMD_REG); + writel(WDT_START_2, wdt->base + WDT_CMD_REG); + + return 0; +} + +static int bcm7038_wdt_start(struct watchdog_device *wdog) +{ + bcm7038_wdt_set_timeout_reg(wdog); + bcm7038_wdt_ping(wdog); + + return 0; +} + +static int bcm7038_wdt_stop(struct watchdog_device *wdog) +{ + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); + + writel(WDT_STOP_1, wdt->base + WDT_CMD_REG); + writel(WDT_STOP_2, wdt->base + WDT_CMD_REG); + + return 0; +} + +static int bcm7038_wdt_set_timeout(struct watchdog_device *wdog, + unsigned int t) +{ + /* Can't modify timeout value if watchdog timer is running */ + bcm7038_wdt_stop(wdog); + wdog->timeout = t; + bcm7038_wdt_start(wdog); + + return 0; +} + +static unsigned int bcm7038_wdt_get_timeleft(struct watchdog_device *wdog) +{ + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); + u32 time_left; + + time_left = readl(wdt->base + WDT_CMD_REG); + + return time_left / wdt->rate; +} + +static struct watchdog_info bcm7038_wdt_info = { + .identity = "Broadcom BCM7038 Watchdog Timer", + .options= WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | + WDIOF_MAGICCLOSE +}; + +static struct watchdog_ops bcm7038_wdt_ops = { + .owner = THIS_MODULE, + .start = bcm7038_wdt_start, + .stop = bcm7038_wdt_stop, + .set_timeout= bcm7038_wdt_set_timeout, + .get_timeleft = bcm7038_wdt_get_timeleft, +}; + +static int bcm7038_wdt_probe(struct platform_device *pdev) +{ + struct devic
[PATCH v2 2/2] watchdog: Watchdog driver for Broadcom Set-Top Box
Watchdog driver for Broadcom 7038 and newer chips. Signed-off-by: Justin Chen --- drivers/watchdog/Kconfig | 8 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/bcm7038_wdt.c | 235 + 3 files changed, 244 insertions(+) create mode 100644 drivers/watchdog/bcm7038_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 241fafd..4fbe8ab 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -1291,6 +1291,14 @@ config BCM_KONA_WDT_DEBUG If in doubt, say 'N'. +config BCM7038_WDT + tristate "BCM7038 Watchdog" + select WATCHDOG_CORE + help +Watchdog driver for the built-in hardware in Broadcom 7038 SoCs. + +Say 'Y or 'M' here to enable the driver. + config IMGPDC_WDT tristate "Imagination Technologies PDC Watchdog Timer" depends on HAS_IOMEM diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 59ea9a1..65d4169 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_TEGRA_WATCHDOG) += tegra_wdt.o obj-$(CONFIG_MESON_WATCHDOG) += meson_wdt.o obj-$(CONFIG_MEDIATEK_WATCHDOG) += mtk_wdt.o obj-$(CONFIG_DIGICOLOR_WATCHDOG) += digicolor_wdt.o +obj-$(CONFIG_BCM7038_WDT) += bcm7038_wdt.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o diff --git a/drivers/watchdog/bcm7038_wdt.c b/drivers/watchdog/bcm7038_wdt.c new file mode 100644 index 000..5e54c1b --- /dev/null +++ b/drivers/watchdog/bcm7038_wdt.c @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2015 Broadcom Corporation + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define WDT_START_10xff00 +#define WDT_START_20x00ff +#define WDT_STOP_1 0xee00 +#define WDT_STOP_2 0x00ee + +#define WDT_TIMEOUT_REG0x0 +#define WDT_CMD_REG0x4 + +#define WDT_MIN_TIMEOUT1 /* seconds */ +#define WDT_DEFAULT_TIMEOUT30 /* seconds */ +#define WDT_DEFAULT_RATE 2700 + +struct bcm7038_watchdog { + void __iomem*base; + struct watchdog_device wdd; + u32 rate; + struct clk *clk; +}; + +static bool nowayout = WATCHDOG_NOWAYOUT; + +static void bcm7038_wdt_set_timeout_reg(struct watchdog_device *wdog) +{ + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); + u32 timeout; + + timeout = wdt->rate * wdog->timeout; + + writel(timeout, wdt->base + WDT_TIMEOUT_REG); +} + +static int bcm7038_wdt_ping(struct watchdog_device *wdog) +{ + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); + + writel(WDT_START_1, wdt->base + WDT_CMD_REG); + writel(WDT_START_2, wdt->base + WDT_CMD_REG); + + return 0; +} + +static int bcm7038_wdt_start(struct watchdog_device *wdog) +{ + bcm7038_wdt_set_timeout_reg(wdog); + bcm7038_wdt_ping(wdog); + + return 0; +} + +static int bcm7038_wdt_stop(struct watchdog_device *wdog) +{ + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); + + writel(WDT_STOP_1, wdt->base + WDT_CMD_REG); + writel(WDT_STOP_2, wdt->base + WDT_CMD_REG); + + return 0; +} + +static int bcm7038_wdt_set_timeout(struct watchdog_device *wdog, + unsigned int t) +{ + /* Can't modify timeout value if watchdog timer is running */ + bcm7038_wdt_stop(wdog); + wdog->timeout = t; + bcm7038_wdt_start(wdog); + + return 0; +} + +static unsigned int bcm7038_wdt_get_timeleft(struct watchdog_device *wdog) +{ + struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog); + u32 time_left; + + time_left = readl(wdt->base + WDT_CMD_REG); + + return time_left / wdt->rate; +} + +static struct watchdog_info bcm7038_wdt_info = { + .identity = "Broadcom BCM7038 Watchdog Timer", + .options= WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | + WDIOF_MAGICCLOSE +}; + +static struct watchdog_ops bcm7038_wdt_ops = { + .owner = THIS_MODULE, + .start = bcm7038_wdt_start, + .stop = bcm7038_wdt_stop, + .set_timeout= bcm7038_wdt_set_timeout, + .get_timeleft = bcm7038_wdt_get_timeleft, +}; + +static int bcm7038_wdt_probe(struct platform_device *pdev) +{ + struct devic