* [PATCH v3 0/5] STM32 Independant watchdog @ 2017-03-22 15:04 Yannick Fertre 2017-03-22 15:04 ` [PATCH v3 1/5] dt-bindings: Document STM32 IWDG bindings Yannick Fertre ` (5 more replies) 0 siblings, 6 replies; 12+ messages in thread From: Yannick Fertre @ 2017-03-22 15:04 UTC (permalink / raw) To: Wim Van Sebroeck, Guenter Roeck, Rob Herring, Alexandre TORGUE, Benjamin Gaignard, Yannick Fertre, Maxime Coquelin Cc: linux-watchdog, linux-kernel, Philippe Cornu, Gabriel FERNANDEZ, devicetree, linux-arm-kernel Version 3: - Update typo into bindings file - Reorder node in devicetree (ordering by address) - Remove unecessary lines in commits Version 2: - Add commit messages Version 1: - Initial commit The purpose of this set of patches is to add a new watchdog driver for stm32f429. This driver was developed and tested on evaluation board stm32429i. Yannick Fertre (5): dt-bindings: Document STM32 IWDG bindings drivers: watchdog: Add STM32 IWDG driver ARM: dts: stm32: Add watchdog support for STM32F429 SoC ARM: dts: stm32: Add watchdog support for STM32F429 eval board ARM: configs: Add watchdog support in STM32 defconfig .../devicetree/bindings/watchdog/st,stm32-iwdg.txt | 15 ++ arch/arm/boot/dts/stm32429i-eval.dts | 4 + arch/arm/boot/dts/stm32f429.dtsi | 9 +- arch/arm/configs/stm32_defconfig | 1 + drivers/watchdog/Kconfig | 11 + drivers/watchdog/Makefile | 1 + drivers/watchdog/stm32_iwdg.c | 289 +++++++++++++++++++++ 7 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt create mode 100644 drivers/watchdog/stm32_iwdg.c -- 1.9.1 ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 1/5] dt-bindings: Document STM32 IWDG bindings 2017-03-22 15:04 [PATCH v3 0/5] STM32 Independant watchdog Yannick Fertre @ 2017-03-22 15:04 ` Yannick Fertre 2017-03-29 1:40 ` Rob Herring 2017-03-29 3:15 ` Guenter Roeck 2017-03-22 15:04 ` [PATCH v3 2/5] drivers: watchdog: Add STM32 IWDG driver Yannick Fertre ` (4 subsequent siblings) 5 siblings, 2 replies; 12+ messages in thread From: Yannick Fertre @ 2017-03-22 15:04 UTC (permalink / raw) To: Wim Van Sebroeck, Guenter Roeck, Rob Herring, Alexandre TORGUE, Benjamin Gaignard, Yannick Fertre, Maxime Coquelin Cc: linux-watchdog, linux-kernel, Philippe Cornu, Gabriel FERNANDEZ, devicetree, linux-arm-kernel From: Yannick Fertre <yfertre.stm32@gmail.com> This adds documentation of device tree bindings for the STM32 IWDG (Independent WatchDoG). Change-Id: Idadacc806d00205fe9af2e8606af229b4b760558 Signed-off-by: Yannick Fertre <yannick.fertre@st.com> --- .../devicetree/bindings/watchdog/st,stm32-iwdg.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt diff --git a/Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt b/Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt new file mode 100644 index 0000000..036b040 --- /dev/null +++ b/Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt @@ -0,0 +1,15 @@ +STM32 Independent WatchDoG (IWDG) +--------------------------------- + +Required properties: +- compatible: "st,stm32-iwdg" +- reg: physical base address and length of the registers set for the device +- clocks: must contain a single entry describing the clock input + +Example: + +iwdg@40003000 { + compatible = "st,stm32-iwdg"; + reg = <0x40003000 0x400>; + clocks = <&clk_lsi>; +}; -- 1.9.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v3 1/5] dt-bindings: Document STM32 IWDG bindings 2017-03-22 15:04 ` [PATCH v3 1/5] dt-bindings: Document STM32 IWDG bindings Yannick Fertre @ 2017-03-29 1:40 ` Rob Herring 2017-03-29 3:15 ` Guenter Roeck 1 sibling, 0 replies; 12+ messages in thread From: Rob Herring @ 2017-03-29 1:40 UTC (permalink / raw) To: Yannick Fertre Cc: Wim Van Sebroeck, Guenter Roeck, Alexandre TORGUE, Benjamin Gaignard, Maxime Coquelin, linux-watchdog, linux-kernel, Philippe Cornu, Gabriel FERNANDEZ, devicetree, linux-arm-kernel On Wed, Mar 22, 2017 at 04:04:39PM +0100, Yannick Fertre wrote: > From: Yannick Fertre <yfertre.stm32@gmail.com> "dt-bindings: watchdog: ..." for subject. > > This adds documentation of device tree bindings for the STM32 IWDG > (Independent WatchDoG). > > Change-Id: Idadacc806d00205fe9af2e8606af229b4b760558 > Signed-off-by: Yannick Fertre <yannick.fertre@st.com> > --- > .../devicetree/bindings/watchdog/st,stm32-iwdg.txt | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > create mode 100644 Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt > > diff --git a/Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt b/Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt > new file mode 100644 > index 0000000..036b040 > --- /dev/null > +++ b/Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt > @@ -0,0 +1,15 @@ > +STM32 Independent WatchDoG (IWDG) > +--------------------------------- > + > +Required properties: > +- compatible: "st,stm32-iwdg" > +- reg: physical base address and length of the registers set for the device > +- clocks: must contain a single entry describing the clock input > + > +Example: > + > +iwdg@40003000 { watchdog@... > + compatible = "st,stm32-iwdg"; > + reg = <0x40003000 0x400>; > + clocks = <&clk_lsi>; > +}; > -- > 1.9.1 > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 1/5] dt-bindings: Document STM32 IWDG bindings 2017-03-22 15:04 ` [PATCH v3 1/5] dt-bindings: Document STM32 IWDG bindings Yannick Fertre 2017-03-29 1:40 ` Rob Herring @ 2017-03-29 3:15 ` Guenter Roeck 1 sibling, 0 replies; 12+ messages in thread From: Guenter Roeck @ 2017-03-29 3:15 UTC (permalink / raw) To: Yannick Fertre, Wim Van Sebroeck, Rob Herring, Alexandre TORGUE, Benjamin Gaignard, Maxime Coquelin Cc: linux-watchdog, linux-kernel, Philippe Cornu, Gabriel FERNANDEZ, devicetree, linux-arm-kernel On 03/22/2017 08:04 AM, Yannick Fertre wrote: > From: Yannick Fertre <yfertre.stm32@gmail.com> > > This adds documentation of device tree bindings for the STM32 IWDG > (Independent WatchDoG). > > Change-Id: Idadacc806d00205fe9af2e8606af229b4b760558 Please drop. > Signed-off-by: Yannick Fertre <yannick.fertre@st.com> > --- > .../devicetree/bindings/watchdog/st,stm32-iwdg.txt | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > create mode 100644 Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt > > diff --git a/Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt b/Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt > new file mode 100644 > index 0000000..036b040 > --- /dev/null > +++ b/Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt > @@ -0,0 +1,15 @@ > +STM32 Independent WatchDoG (IWDG) > +--------------------------------- > + > +Required properties: > +- compatible: "st,stm32-iwdg" > +- reg: physical base address and length of the registers set for the device > +- clocks: must contain a single entry describing the clock input > + > +Example: > + > +iwdg@40003000 { > + compatible = "st,stm32-iwdg"; > + reg = <0x40003000 0x400>; > + clocks = <&clk_lsi>; > +}; > ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 2/5] drivers: watchdog: Add STM32 IWDG driver 2017-03-22 15:04 [PATCH v3 0/5] STM32 Independant watchdog Yannick Fertre 2017-03-22 15:04 ` [PATCH v3 1/5] dt-bindings: Document STM32 IWDG bindings Yannick Fertre @ 2017-03-22 15:04 ` Yannick Fertre 2017-03-29 3:15 ` Guenter Roeck 2017-03-22 15:04 ` [PATCH v3 3/5] ARM: dts: stm32: Add watchdog support for STM32F429 SoC Yannick Fertre ` (3 subsequent siblings) 5 siblings, 1 reply; 12+ messages in thread From: Yannick Fertre @ 2017-03-22 15:04 UTC (permalink / raw) To: Wim Van Sebroeck, Guenter Roeck, Rob Herring, Alexandre TORGUE, Benjamin Gaignard, Yannick Fertre, Maxime Coquelin Cc: linux-watchdog, linux-kernel, Philippe Cornu, Gabriel FERNANDEZ, devicetree, linux-arm-kernel This patch adds IWDG (Independent WatchDoG) support for STM32 platform. Change-Id: Iab218745fc25566f12558fae7f52e2f8c21db74e Signed-off-by: Yannick FERTRE <yannick.fertre@st.com> --- drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/stm32_iwdg.c | 289 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/watchdog/stm32_iwdg.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 52a70ee..d9745a5 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -744,6 +744,17 @@ config ZX2967_WATCHDOG To compile this driver as a module, choose M here: the module will be called zx2967_wdt. +config STM32_WATCHDOG + tristate "STM32 Independent WatchDoG (IWDG) support" + depends on ARCH_STM32 + select WATCHDOG_CORE + default y + help + Say Y here to include Watchdog timer support. + + To compile this driver as a module, choose M here: the + module will be called stm32_iwdg. + # AVR32 Architecture config AT32AP700X_WDT diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index a2126e2..a35e423 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -84,6 +84,7 @@ obj-$(CONFIG_ATLAS7_WATCHDOG) += atlas7_wdt.o obj-$(CONFIG_RENESAS_WDT) += renesas_wdt.o obj-$(CONFIG_ASPEED_WATCHDOG) += aspeed_wdt.o obj-$(CONFIG_ZX2967_WATCHDOG) += zx2967_wdt.o +obj-$(CONFIG_STM32_WATCHDOG) += stm32_iwdg.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c new file mode 100644 index 0000000..507dfc4 --- /dev/null +++ b/drivers/watchdog/stm32_iwdg.c @@ -0,0 +1,289 @@ +/* + * Driver for STM32 Independent Watchdog + * + * Copyright (C) Yannick Fertre 2017 + * Author: Yannick Fertre <yannick.fertre@st.com> + * + * This driver is based on tegra_wdt.c + * + * License terms: GNU General Public License (GPL), version 2 + */ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/watchdog.h> + +/* minimum watchdog trigger timeout, in seconds */ +#define MIN_WDT_TIMEOUT 1 + +/* IWDG registers */ +#define IWDG_KR 0x00 /* Key register */ +#define IWDG_PR 0x04 /* Prescaler Register */ +#define IWDG_RLR 0x08 /* ReLoad Register */ +#define IWDG_SR 0x0C /* Status Register */ +#define IWDG_WINR 0x10 /* Windows Register */ + +/* IWDG_KR register bit mask */ +#define KR_KEY_RELOAD 0xAAAA /* reload counter enable */ +#define KR_KEY_ENABLE 0xCCCC /* peripheral enable */ +#define KR_KEY_EWA 0x5555 /* write access enable */ +#define KR_KEY_DWA 0x0000 /* write access disable */ + +/* IWDG_PR register bit values */ +#define PR_4 0x00 /* prescaler set to 4 */ +#define PR_8 0x01 /* prescaler set to 8 */ +#define PR_16 0x02 /* prescaler set to 16 */ +#define PR_32 0x03 /* prescaler set to 32 */ +#define PR_64 0x04 /* prescaler set to 64 */ +#define PR_128 0x05 /* prescaler set to 128 */ +#define PR_256 0x06 /* prescaler set to 256 */ + +/* IWDG_RLR register values */ +#define RLR_MAX 0xFFF /* max value supported by reload register */ + +/* IWDG_SR register bit mask */ +#define FLAG_PVU BIT(0) /* Watchdog prescaler value update */ +#define FLAG_RVU BIT(1) /* Watchdog counter reload value update */ + +/* set timeout to 100000 us */ +#define TIMEOUT_US 100000 +#define SLEEP_US 1000 + +struct stm32_iwdg { + struct watchdog_device wdd; + struct device *dev; + void __iomem *regs; + struct clk *clk; + unsigned int rate; +}; + +static int heartbeat = MIN_WDT_TIMEOUT; +module_param(heartbeat, int, 0x0); +MODULE_PARM_DESC(heartbeat, + "Watchdog heartbeats in seconds. (default = " + __MODULE_STRING(WDT_HEARTBEAT) ")"); + +static inline u32 reg_read(void __iomem *base, u32 reg) +{ + return readl_relaxed(base + reg); +} + +static inline void reg_write(void __iomem *base, u32 reg, u32 val) +{ + writel_relaxed(val, base + reg); +} + +static int stm32_iwdg_start(struct watchdog_device *wdd) +{ + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); + u32 val = FLAG_PVU | FLAG_RVU; + u32 reload; + int ret; + + dev_dbg(wdt->dev, "%s\n", __func__); + + /* prescaler fixed to 256 */ + reload = (wdd->timeout * wdt->rate) / 256; + if (reload > RLR_MAX + 1) { + dev_err(wdt->dev, + "Watchdog doesn't support reload value: %d\n", reload); + return -EINVAL; + } + + /* enable watchdog */ + reg_write(wdt->regs, IWDG_KR, KR_KEY_ENABLE); + + /* set prescaler & reload registers */ + reg_write(wdt->regs, IWDG_KR, KR_KEY_EWA); + reg_write(wdt->regs, IWDG_PR, PR_256); /* prescaler fix to 256 */ + reg_write(wdt->regs, IWDG_RLR, reload - 1); + + /* wait for the registers to be updated (max 100ms) */ + ret = readl_relaxed_poll_timeout(wdt->regs + IWDG_SR, val, + !(val & (FLAG_PVU | FLAG_RVU)), + SLEEP_US, TIMEOUT_US); + if (ret) { + dev_err(wdt->dev, + "Fail to set prescaler or reload registers\n"); + return -EINVAL; + } + + /* reload watchdog */ + reg_write(wdt->regs, IWDG_KR, KR_KEY_RELOAD); + + return 0; +} + +static int stm32_iwdg_stop(struct watchdog_device *wdd) +{ + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); + + if (watchdog_active(wdd)) { + dev_err(wdt->dev, + "Watchdog can't be stopped once started(no way out)\n"); + return -EPERM; + } + + return 0; +} + +static int stm32_iwdg_ping(struct watchdog_device *wdd) +{ + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); + + dev_dbg(wdt->dev, "%s\n", __func__); + + reg_write(wdt->regs, IWDG_KR, KR_KEY_RELOAD); + + return 0; +} + +static int stm32_iwdg_set_timeout(struct watchdog_device *wdd, + unsigned int timeout) +{ + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); + + dev_dbg(wdt->dev, "%s timeout: %d sec\n", __func__, timeout); + + wdd->timeout = timeout; + + if (watchdog_active(wdd)) + return stm32_iwdg_start(wdd); + + return 0; +} + +static const struct watchdog_info stm32_iwdg_info = { + .options = WDIOF_SETTIMEOUT | + WDIOF_MAGICCLOSE | + WDIOF_KEEPALIVEPING, + .identity = "STM32 Independent Watchdog", +}; + +static struct watchdog_ops stm32_iwdg_ops = { + .owner = THIS_MODULE, + .start = stm32_iwdg_start, + .stop = stm32_iwdg_stop, + .ping = stm32_iwdg_ping, + .set_timeout = stm32_iwdg_set_timeout, +}; + +static int stm32_iwdg_probe(struct platform_device *pdev) +{ + struct watchdog_device *wdd; + struct stm32_iwdg *wdt; + struct resource *res; + void __iomem *regs; + struct clk *clk; + int max_wdt_timeout; + int ret; + + /* This is the timer base. */ + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + regs = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(regs)) { + dev_err(&pdev->dev, "Could not get resource\n"); + return PTR_ERR(regs); + } + + clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(clk)) { + dev_err(&pdev->dev, "Unable to get clock\n"); + return PTR_ERR(clk); + } + + ret = clk_prepare_enable(clk); + if (ret) { + dev_err(&pdev->dev, "Unable to prepare clock %p\n", clk); + return ret; + } + + /* + * Allocate our watchdog driver data, which has the + * struct watchdog_device nested within it. + */ + wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); + if (!wdt) { + ret = -ENOMEM; + goto err; + } + + /* Initialize struct stm32_iwdg. */ + wdt->regs = regs; + wdt->dev = &pdev->dev; + wdt->clk = clk; + /* + * iwdg is clocked by its own dedicated low-speed clock (LSI) + * at 32khz. + */ + wdt->rate = 32 * 1024; + + /* get max timeout & set heartbeat */ + max_wdt_timeout = ((RLR_MAX + 1) * 256) / wdt->rate; + heartbeat = max_wdt_timeout; + + /* Initialize struct watchdog_device. */ + wdd = &wdt->wdd; + wdd->timeout = heartbeat; + wdd->info = &stm32_iwdg_info; + wdd->ops = &stm32_iwdg_ops; + wdd->min_timeout = MIN_WDT_TIMEOUT; + wdd->max_timeout = max_wdt_timeout; + watchdog_set_drvdata(wdd, wdt); + watchdog_set_nowayout(wdd, true); + + ret = watchdog_register_device(wdd); + if (ret) { + dev_err(&pdev->dev, + "failed to register watchdog device\n"); + goto err; + } + + platform_set_drvdata(pdev, wdt); + + dev_info(&pdev->dev, + "initialized (heartbeat = %d sec)\n", heartbeat); + return 0; + +err: + clk_disable_unprepare(clk); + return ret; +} + +static int stm32_iwdg_remove(struct platform_device *pdev) +{ + struct stm32_iwdg *wdt = platform_get_drvdata(pdev); + + watchdog_unregister_device(&wdt->wdd); + clk_disable_unprepare(wdt->clk); + + dev_info(&pdev->dev, "removed watchdog device\n"); + return 0; +} + +static const struct of_device_id stm32_iwdg_of_match[] = { + { .compatible = "st,stm32-iwdg" }, + { /* end node */ } +}; +MODULE_DEVICE_TABLE(of, stm32_iwdg_of_match); + +static struct platform_driver stm32_iwdg_driver = { + .probe = stm32_iwdg_probe, + .remove = stm32_iwdg_remove, + .driver = { + .name = "iwdg", + .of_match_table = stm32_iwdg_of_match, + }, +}; +module_platform_driver(stm32_iwdg_driver); + +MODULE_AUTHOR("Yannick Fertre <yannick.fertre@st.com>"); +MODULE_DESCRIPTION("STMicroelectronics STM32 Independent Watchdog Driver"); +MODULE_LICENSE("GPL v2"); -- 1.9.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v3 2/5] drivers: watchdog: Add STM32 IWDG driver 2017-03-22 15:04 ` [PATCH v3 2/5] drivers: watchdog: Add STM32 IWDG driver Yannick Fertre @ 2017-03-29 3:15 ` Guenter Roeck 2017-03-30 15:10 ` Yannick FERTRE 0 siblings, 1 reply; 12+ messages in thread From: Guenter Roeck @ 2017-03-29 3:15 UTC (permalink / raw) To: Yannick Fertre, Wim Van Sebroeck, Rob Herring, Alexandre TORGUE, Benjamin Gaignard, Maxime Coquelin Cc: linux-watchdog, linux-kernel, Philippe Cornu, Gabriel FERNANDEZ, devicetree, linux-arm-kernel On 03/22/2017 08:04 AM, Yannick Fertre wrote: > This patch adds IWDG (Independent WatchDoG) support for STM32 platform. > > Change-Id: Iab218745fc25566f12558fae7f52e2f8c21db74e No gerrit tags, please. > Signed-off-by: Yannick FERTRE <yannick.fertre@st.com> > --- > drivers/watchdog/Kconfig | 11 ++ > drivers/watchdog/Makefile | 1 + > drivers/watchdog/stm32_iwdg.c | 289 ++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 301 insertions(+) > create mode 100644 drivers/watchdog/stm32_iwdg.c > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig > index 52a70ee..d9745a5 100644 > --- a/drivers/watchdog/Kconfig > +++ b/drivers/watchdog/Kconfig > @@ -744,6 +744,17 @@ config ZX2967_WATCHDOG > To compile this driver as a module, choose M here: the > module will be called zx2967_wdt. > > +config STM32_WATCHDOG > + tristate "STM32 Independent WatchDoG (IWDG) support" > + depends on ARCH_STM32 > + select WATCHDOG_CORE > + default y > + help > + Say Y here to include Watchdog timer support. ... for <pick your text>. > + > + To compile this driver as a module, choose M here: the > + module will be called stm32_iwdg. > + > # AVR32 Architecture > > config AT32AP700X_WDT > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile > index a2126e2..a35e423 100644 > --- a/drivers/watchdog/Makefile > +++ b/drivers/watchdog/Makefile > @@ -84,6 +84,7 @@ obj-$(CONFIG_ATLAS7_WATCHDOG) += atlas7_wdt.o > obj-$(CONFIG_RENESAS_WDT) += renesas_wdt.o > obj-$(CONFIG_ASPEED_WATCHDOG) += aspeed_wdt.o > obj-$(CONFIG_ZX2967_WATCHDOG) += zx2967_wdt.o > +obj-$(CONFIG_STM32_WATCHDOG) += stm32_iwdg.o > > # AVR32 Architecture > obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o > diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c > new file mode 100644 > index 0000000..507dfc4 > --- /dev/null > +++ b/drivers/watchdog/stm32_iwdg.c > @@ -0,0 +1,289 @@ > +/* > + * Driver for STM32 Independent Watchdog > + * > + * Copyright (C) Yannick Fertre 2017 > + * Author: Yannick Fertre <yannick.fertre@st.com> > + * > + * This driver is based on tegra_wdt.c > + * > + * License terms: GNU General Public License (GPL), version 2 > + */ > + > +#include <linux/clk.h> > +#include <linux/delay.h> > +#include <linux/kernel.h> > +#include <linux/module.h> > +#include <linux/interrupt.h> > +#include <linux/io.h> > +#include <linux/iopoll.h> > +#include <linux/of.h> > +#include <linux/platform_device.h> > +#include <linux/watchdog.h> > + > +/* minimum watchdog trigger timeout, in seconds */ > +#define MIN_WDT_TIMEOUT 1 > + > +/* IWDG registers */ > +#define IWDG_KR 0x00 /* Key register */ > +#define IWDG_PR 0x04 /* Prescaler Register */ > +#define IWDG_RLR 0x08 /* ReLoad Register */ > +#define IWDG_SR 0x0C /* Status Register */ > +#define IWDG_WINR 0x10 /* Windows Register */ > + > +/* IWDG_KR register bit mask */ > +#define KR_KEY_RELOAD 0xAAAA /* reload counter enable */ > +#define KR_KEY_ENABLE 0xCCCC /* peripheral enable */ > +#define KR_KEY_EWA 0x5555 /* write access enable */ > +#define KR_KEY_DWA 0x0000 /* write access disable */ > + > +/* IWDG_PR register bit values */ > +#define PR_4 0x00 /* prescaler set to 4 */ > +#define PR_8 0x01 /* prescaler set to 8 */ > +#define PR_16 0x02 /* prescaler set to 16 */ > +#define PR_32 0x03 /* prescaler set to 32 */ > +#define PR_64 0x04 /* prescaler set to 64 */ > +#define PR_128 0x05 /* prescaler set to 128 */ > +#define PR_256 0x06 /* prescaler set to 256 */ > + > +/* IWDG_RLR register values */ > +#define RLR_MAX 0xFFF /* max value supported by reload register */ > + > +/* IWDG_SR register bit mask */ > +#define FLAG_PVU BIT(0) /* Watchdog prescaler value update */ > +#define FLAG_RVU BIT(1) /* Watchdog counter reload value update */ > + > +/* set timeout to 100000 us */ > +#define TIMEOUT_US 100000 > +#define SLEEP_US 1000 > + > +struct stm32_iwdg { > + struct watchdog_device wdd; > + struct device *dev; > + void __iomem *regs; > + struct clk *clk; > + unsigned int rate; > +}; > + > +static int heartbeat = MIN_WDT_TIMEOUT; > +module_param(heartbeat, int, 0x0); > +MODULE_PARM_DESC(heartbeat, > + "Watchdog heartbeats in seconds. (default = " > + __MODULE_STRING(WDT_HEARTBEAT) ")"); > + > +static inline u32 reg_read(void __iomem *base, u32 reg) > +{ > + return readl_relaxed(base + reg); > +} > + > +static inline void reg_write(void __iomem *base, u32 reg, u32 val) > +{ > + writel_relaxed(val, base + reg); > +} > + > +static int stm32_iwdg_start(struct watchdog_device *wdd) > +{ > + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); > + u32 val = FLAG_PVU | FLAG_RVU; > + u32 reload; > + int ret; > + > + dev_dbg(wdt->dev, "%s\n", __func__); > + > + /* prescaler fixed to 256 */ > + reload = (wdd->timeout * wdt->rate) / 256; > + if (reload > RLR_MAX + 1) { > + dev_err(wdt->dev, > + "Watchdog doesn't support reload value: %d\n", reload); > + return -EINVAL; > + } This should not happen if min_timeout and max_timeout are set properly. > + > + /* enable watchdog */ > + reg_write(wdt->regs, IWDG_KR, KR_KEY_ENABLE); > + > + /* set prescaler & reload registers */ > + reg_write(wdt->regs, IWDG_KR, KR_KEY_EWA); > + reg_write(wdt->regs, IWDG_PR, PR_256); /* prescaler fix to 256 */ > + reg_write(wdt->regs, IWDG_RLR, reload - 1); > + > + /* wait for the registers to be updated (max 100ms) */ > + ret = readl_relaxed_poll_timeout(wdt->regs + IWDG_SR, val, > + !(val & (FLAG_PVU | FLAG_RVU)), > + SLEEP_US, TIMEOUT_US); > + if (ret) { > + dev_err(wdt->dev, > + "Fail to set prescaler or reload registers\n"); > + return -EINVAL; Any reason for overriding the return value ? > + } > + > + /* reload watchdog */ > + reg_write(wdt->regs, IWDG_KR, KR_KEY_RELOAD); > + > + return 0; > +} > + > +static int stm32_iwdg_stop(struct watchdog_device *wdd) > +{ > + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); > + > + if (watchdog_active(wdd)) { > + dev_err(wdt->dev, > + "Watchdog can't be stopped once started(no way out)\n"); > + return -EPERM; The infrastructure takes care of this. Don't provide a stop function, and provide the maximum hardware timeout. > + } > + > + return 0; > +} > + > +static int stm32_iwdg_ping(struct watchdog_device *wdd) > +{ > + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); > + > + dev_dbg(wdt->dev, "%s\n", __func__); > + > + reg_write(wdt->regs, IWDG_KR, KR_KEY_RELOAD); > + > + return 0; > +} > + > +static int stm32_iwdg_set_timeout(struct watchdog_device *wdd, > + unsigned int timeout) > +{ > + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); > + > + dev_dbg(wdt->dev, "%s timeout: %d sec\n", __func__, timeout); > + > + wdd->timeout = timeout; > + > + if (watchdog_active(wdd)) > + return stm32_iwdg_start(wdd); > + > + return 0; > +} > + > +static const struct watchdog_info stm32_iwdg_info = { > + .options = WDIOF_SETTIMEOUT | > + WDIOF_MAGICCLOSE | > + WDIOF_KEEPALIVEPING, > + .identity = "STM32 Independent Watchdog", > +}; > + > +static struct watchdog_ops stm32_iwdg_ops = { > + .owner = THIS_MODULE, > + .start = stm32_iwdg_start, > + .stop = stm32_iwdg_stop, > + .ping = stm32_iwdg_ping, > + .set_timeout = stm32_iwdg_set_timeout, > +}; > + > +static int stm32_iwdg_probe(struct platform_device *pdev) > +{ > + struct watchdog_device *wdd; > + struct stm32_iwdg *wdt; > + struct resource *res; > + void __iomem *regs; > + struct clk *clk; > + int max_wdt_timeout; > + int ret; > + > + /* This is the timer base. */ > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + regs = devm_ioremap_resource(&pdev->dev, res); > + if (IS_ERR(regs)) { > + dev_err(&pdev->dev, "Could not get resource\n"); > + return PTR_ERR(regs); > + } > + > + clk = devm_clk_get(&pdev->dev, NULL); > + if (IS_ERR(clk)) { > + dev_err(&pdev->dev, "Unable to get clock\n"); > + return PTR_ERR(clk); > + } > + > + ret = clk_prepare_enable(clk); > + if (ret) { > + dev_err(&pdev->dev, "Unable to prepare clock %p\n", clk); > + return ret; > + } > + > + /* > + * Allocate our watchdog driver data, which has the > + * struct watchdog_device nested within it. > + */ > + wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); > + if (!wdt) { > + ret = -ENOMEM; > + goto err; > + } > + > + /* Initialize struct stm32_iwdg. */ > + wdt->regs = regs; > + wdt->dev = &pdev->dev; > + wdt->clk = clk; > + /* > + * iwdg is clocked by its own dedicated low-speed clock (LSI) > + * at 32khz. > + */ > + wdt->rate = 32 * 1024; Why not clk_get_rate() ? > + > + /* get max timeout & set heartbeat */ > + max_wdt_timeout = ((RLR_MAX + 1) * 256) / wdt->rate; > + heartbeat = max_wdt_timeout; What is the value of overwriting this variable ? Why don't you just use max_wdt_timeout, and what is the point of making heartbeat configurable if you overwrite it anyway ? I would suggest to use watchdog_init_timeout() to set optional non-default timeout values, especially since this also enables getting the timeout value from devicetree. > + > + /* Initialize struct watchdog_device. */ > + wdd = &wdt->wdd; > + wdd->timeout = heartbeat; > + wdd->info = &stm32_iwdg_info; > + wdd->ops = &stm32_iwdg_ops; > + wdd->min_timeout = MIN_WDT_TIMEOUT; > + wdd->max_timeout = max_wdt_timeout; You might want to consider setting max_hw_heartbeat_ms instead and drop the stop function. > + watchdog_set_drvdata(wdd, wdt); > + watchdog_set_nowayout(wdd, true); > + > + ret = watchdog_register_device(wdd); > + if (ret) { > + dev_err(&pdev->dev, > + "failed to register watchdog device\n"); > + goto err; > + } > + > + platform_set_drvdata(pdev, wdt); > + > + dev_info(&pdev->dev, > + "initialized (heartbeat = %d sec)\n", heartbeat); > + return 0; > + > +err: > + clk_disable_unprepare(clk); > + return ret; > +} > + > +static int stm32_iwdg_remove(struct platform_device *pdev) > +{ > + struct stm32_iwdg *wdt = platform_get_drvdata(pdev); > + > + watchdog_unregister_device(&wdt->wdd); > + clk_disable_unprepare(wdt->clk); > + > + dev_info(&pdev->dev, "removed watchdog device\n"); Is this message really useful ? I think it is just noise. > + return 0; > +} > + > +static const struct of_device_id stm32_iwdg_of_match[] = { > + { .compatible = "st,stm32-iwdg" }, > + { /* end node */ } > +}; > +MODULE_DEVICE_TABLE(of, stm32_iwdg_of_match); > + > +static struct platform_driver stm32_iwdg_driver = { > + .probe = stm32_iwdg_probe, > + .remove = stm32_iwdg_remove, > + .driver = { > + .name = "iwdg", > + .of_match_table = stm32_iwdg_of_match, > + }, > +}; > +module_platform_driver(stm32_iwdg_driver); > + > +MODULE_AUTHOR("Yannick Fertre <yannick.fertre@st.com>"); > +MODULE_DESCRIPTION("STMicroelectronics STM32 Independent Watchdog Driver"); > +MODULE_LICENSE("GPL v2"); > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 2/5] drivers: watchdog: Add STM32 IWDG driver 2017-03-29 3:15 ` Guenter Roeck @ 2017-03-30 15:10 ` Yannick FERTRE 0 siblings, 0 replies; 12+ messages in thread From: Yannick FERTRE @ 2017-03-30 15:10 UTC (permalink / raw) To: Guenter Roeck, Wim Van Sebroeck, Rob Herring, Alexandre TORGUE, Benjamin GAIGNARD, Maxime Coquelin Cc: linux-watchdog, linux-kernel, Philippe CORNU, Gabriel FERNANDEZ, devicetree, linux-arm-kernel Hi Guenter, Many thanks for your help, I will push corrections to V4. Best regards On 03/29/2017 05:15 AM, Guenter Roeck wrote: > On 03/22/2017 08:04 AM, Yannick Fertre wrote: >> This patch adds IWDG (Independent WatchDoG) support for STM32 platform. >> >> Change-Id: Iab218745fc25566f12558fae7f52e2f8c21db74e > > No gerrit tags, please. > >> Signed-off-by: Yannick FERTRE <yannick.fertre@st.com> >> --- >> drivers/watchdog/Kconfig | 11 ++ >> drivers/watchdog/Makefile | 1 + >> drivers/watchdog/stm32_iwdg.c | 289 >> ++++++++++++++++++++++++++++++++++++++++++ >> 3 files changed, 301 insertions(+) >> create mode 100644 drivers/watchdog/stm32_iwdg.c >> >> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig >> index 52a70ee..d9745a5 100644 >> --- a/drivers/watchdog/Kconfig >> +++ b/drivers/watchdog/Kconfig >> @@ -744,6 +744,17 @@ config ZX2967_WATCHDOG >> To compile this driver as a module, choose M here: the >> module will be called zx2967_wdt. >> >> +config STM32_WATCHDOG >> + tristate "STM32 Independent WatchDoG (IWDG) support" >> + depends on ARCH_STM32 >> + select WATCHDOG_CORE >> + default y >> + help >> + Say Y here to include Watchdog timer support. > > ... for <pick your text>. Ok done > >> + >> + To compile this driver as a module, choose M here: the >> + module will be called stm32_iwdg. >> + >> # AVR32 Architecture >> >> config AT32AP700X_WDT >> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile >> index a2126e2..a35e423 100644 >> --- a/drivers/watchdog/Makefile >> +++ b/drivers/watchdog/Makefile >> @@ -84,6 +84,7 @@ obj-$(CONFIG_ATLAS7_WATCHDOG) += atlas7_wdt.o >> obj-$(CONFIG_RENESAS_WDT) += renesas_wdt.o >> obj-$(CONFIG_ASPEED_WATCHDOG) += aspeed_wdt.o >> obj-$(CONFIG_ZX2967_WATCHDOG) += zx2967_wdt.o >> +obj-$(CONFIG_STM32_WATCHDOG) += stm32_iwdg.o >> >> # AVR32 Architecture >> obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o >> diff --git a/drivers/watchdog/stm32_iwdg.c >> b/drivers/watchdog/stm32_iwdg.c >> new file mode 100644 >> index 0000000..507dfc4 >> --- /dev/null >> +++ b/drivers/watchdog/stm32_iwdg.c >> @@ -0,0 +1,289 @@ >> +/* >> + * Driver for STM32 Independent Watchdog >> + * >> + * Copyright (C) Yannick Fertre 2017 >> + * Author: Yannick Fertre <yannick.fertre@st.com> >> + * >> + * This driver is based on tegra_wdt.c >> + * >> + * License terms: GNU General Public License (GPL), version 2 >> + */ >> + >> +#include <linux/clk.h> >> +#include <linux/delay.h> >> +#include <linux/kernel.h> >> +#include <linux/module.h> >> +#include <linux/interrupt.h> >> +#include <linux/io.h> >> +#include <linux/iopoll.h> >> +#include <linux/of.h> >> +#include <linux/platform_device.h> >> +#include <linux/watchdog.h> >> + >> +/* minimum watchdog trigger timeout, in seconds */ >> +#define MIN_WDT_TIMEOUT 1 >> + >> +/* IWDG registers */ >> +#define IWDG_KR 0x00 /* Key register */ >> +#define IWDG_PR 0x04 /* Prescaler Register */ >> +#define IWDG_RLR 0x08 /* ReLoad Register */ >> +#define IWDG_SR 0x0C /* Status Register */ >> +#define IWDG_WINR 0x10 /* Windows Register */ >> + >> +/* IWDG_KR register bit mask */ >> +#define KR_KEY_RELOAD 0xAAAA /* reload counter enable */ >> +#define KR_KEY_ENABLE 0xCCCC /* peripheral enable */ >> +#define KR_KEY_EWA 0x5555 /* write access enable */ >> +#define KR_KEY_DWA 0x0000 /* write access disable */ >> + >> +/* IWDG_PR register bit values */ >> +#define PR_4 0x00 /* prescaler set to 4 */ >> +#define PR_8 0x01 /* prescaler set to 8 */ >> +#define PR_16 0x02 /* prescaler set to 16 */ >> +#define PR_32 0x03 /* prescaler set to 32 */ >> +#define PR_64 0x04 /* prescaler set to 64 */ >> +#define PR_128 0x05 /* prescaler set to 128 */ >> +#define PR_256 0x06 /* prescaler set to 256 */ >> + >> +/* IWDG_RLR register values */ >> +#define RLR_MAX 0xFFF /* max value supported by reload >> register */ >> + >> +/* IWDG_SR register bit mask */ >> +#define FLAG_PVU BIT(0) /* Watchdog prescaler value update */ >> +#define FLAG_RVU BIT(1) /* Watchdog counter reload value update */ >> + >> +/* set timeout to 100000 us */ >> +#define TIMEOUT_US 100000 >> +#define SLEEP_US 1000 >> + >> +struct stm32_iwdg { >> + struct watchdog_device wdd; >> + struct device *dev; >> + void __iomem *regs; >> + struct clk *clk; >> + unsigned int rate; >> +}; >> + >> +static int heartbeat = MIN_WDT_TIMEOUT; >> +module_param(heartbeat, int, 0x0); >> +MODULE_PARM_DESC(heartbeat, >> + "Watchdog heartbeats in seconds. (default = " >> + __MODULE_STRING(WDT_HEARTBEAT) ")"); >> + >> +static inline u32 reg_read(void __iomem *base, u32 reg) >> +{ >> + return readl_relaxed(base + reg); >> +} >> + >> +static inline void reg_write(void __iomem *base, u32 reg, u32 val) >> +{ >> + writel_relaxed(val, base + reg); >> +} >> + >> +static int stm32_iwdg_start(struct watchdog_device *wdd) >> +{ >> + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); >> + u32 val = FLAG_PVU | FLAG_RVU; >> + u32 reload; >> + int ret; >> + >> + dev_dbg(wdt->dev, "%s\n", __func__); >> + >> + /* prescaler fixed to 256 */ >> + reload = (wdd->timeout * wdt->rate) / 256; >> + if (reload > RLR_MAX + 1) { >> + dev_err(wdt->dev, >> + "Watchdog doesn't support reload value: %d\n", reload); >> + return -EINVAL; >> + } > > This should not happen if min_timeout and max_timeout are set properly. > Ok, I remove the test. >> + >> + /* enable watchdog */ >> + reg_write(wdt->regs, IWDG_KR, KR_KEY_ENABLE); >> + >> + /* set prescaler & reload registers */ >> + reg_write(wdt->regs, IWDG_KR, KR_KEY_EWA); >> + reg_write(wdt->regs, IWDG_PR, PR_256); /* prescaler fix to 256 */ >> + reg_write(wdt->regs, IWDG_RLR, reload - 1); >> + >> + /* wait for the registers to be updated (max 100ms) */ >> + ret = readl_relaxed_poll_timeout(wdt->regs + IWDG_SR, val, >> + !(val & (FLAG_PVU | FLAG_RVU)), >> + SLEEP_US, TIMEOUT_US); >> + if (ret) { >> + dev_err(wdt->dev, >> + "Fail to set prescaler or reload registers\n"); >> + return -EINVAL; > > Any reason for overriding the return value ? > Ok, done >> + } >> + >> + /* reload watchdog */ >> + reg_write(wdt->regs, IWDG_KR, KR_KEY_RELOAD); >> + >> + return 0; >> +} >> + >> +static int stm32_iwdg_stop(struct watchdog_device *wdd) >> +{ >> + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); >> + >> + if (watchdog_active(wdd)) { >> + dev_err(wdt->dev, >> + "Watchdog can't be stopped once started(no way out)\n"); >> + return -EPERM; > > The infrastructure takes care of this. Don't provide a stop function, > and provide > the maximum hardware timeout. Ok, I remove stop function > >> + } >> + >> + return 0; >> +} >> + >> +static int stm32_iwdg_ping(struct watchdog_device *wdd) >> +{ >> + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); >> + >> + dev_dbg(wdt->dev, "%s\n", __func__); >> + >> + reg_write(wdt->regs, IWDG_KR, KR_KEY_RELOAD); >> + >> + return 0; >> +} >> + >> +static int stm32_iwdg_set_timeout(struct watchdog_device *wdd, >> + unsigned int timeout) >> +{ >> + struct stm32_iwdg *wdt = watchdog_get_drvdata(wdd); >> + >> + dev_dbg(wdt->dev, "%s timeout: %d sec\n", __func__, timeout); >> + >> + wdd->timeout = timeout; >> + >> + if (watchdog_active(wdd)) >> + return stm32_iwdg_start(wdd); >> + >> + return 0; >> +} >> + >> +static const struct watchdog_info stm32_iwdg_info = { >> + .options = WDIOF_SETTIMEOUT | >> + WDIOF_MAGICCLOSE | >> + WDIOF_KEEPALIVEPING, >> + .identity = "STM32 Independent Watchdog", >> +}; >> + >> +static struct watchdog_ops stm32_iwdg_ops = { >> + .owner = THIS_MODULE, >> + .start = stm32_iwdg_start, >> + .stop = stm32_iwdg_stop, >> + .ping = stm32_iwdg_ping, >> + .set_timeout = stm32_iwdg_set_timeout, >> +}; >> + >> +static int stm32_iwdg_probe(struct platform_device *pdev) >> +{ >> + struct watchdog_device *wdd; >> + struct stm32_iwdg *wdt; >> + struct resource *res; >> + void __iomem *regs; >> + struct clk *clk; >> + int max_wdt_timeout; >> + int ret; >> + >> + /* This is the timer base. */ >> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); >> + regs = devm_ioremap_resource(&pdev->dev, res); >> + if (IS_ERR(regs)) { >> + dev_err(&pdev->dev, "Could not get resource\n"); >> + return PTR_ERR(regs); >> + } >> + >> + clk = devm_clk_get(&pdev->dev, NULL); >> + if (IS_ERR(clk)) { >> + dev_err(&pdev->dev, "Unable to get clock\n"); >> + return PTR_ERR(clk); >> + } >> + >> + ret = clk_prepare_enable(clk); >> + if (ret) { >> + dev_err(&pdev->dev, "Unable to prepare clock %p\n", clk); >> + return ret; >> + } >> + >> + /* >> + * Allocate our watchdog driver data, which has the >> + * struct watchdog_device nested within it. >> + */ >> + wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); >> + if (!wdt) { >> + ret = -ENOMEM; >> + goto err; >> + } >> + >> + /* Initialize struct stm32_iwdg. */ >> + wdt->regs = regs; >> + wdt->dev = &pdev->dev; >> + wdt->clk = clk; >> + /* >> + * iwdg is clocked by its own dedicated low-speed clock (LSI) >> + * at 32khz. >> + */ >> + wdt->rate = 32 * 1024; > > Why not clk_get_rate() ? Ok, done > >> + >> + /* get max timeout & set heartbeat */ >> + max_wdt_timeout = ((RLR_MAX + 1) * 256) / wdt->rate; >> + heartbeat = max_wdt_timeout; > > What is the value of overwriting this variable ? Why don't you just use > max_wdt_timeout, > and what is the point of making heartbeat configurable if you overwrite > it anyway ? > > I would suggest to use watchdog_init_timeout() to set optional non-default > timeout values, especially since this also enables getting the timeout > value from > devicetree. > Ok done >> + >> + /* Initialize struct watchdog_device. */ >> + wdd = &wdt->wdd; >> + wdd->timeout = heartbeat; >> + wdd->info = &stm32_iwdg_info; >> + wdd->ops = &stm32_iwdg_ops; >> + wdd->min_timeout = MIN_WDT_TIMEOUT; >> + wdd->max_timeout = max_wdt_timeout; > > You might want to consider setting max_hw_heartbeat_ms instead and drop > the stop function. > Ok, done >> + watchdog_set_drvdata(wdd, wdt); >> + watchdog_set_nowayout(wdd, true); >> + >> + ret = watchdog_register_device(wdd); >> + if (ret) { >> + dev_err(&pdev->dev, >> + "failed to register watchdog device\n"); >> + goto err; >> + } >> + >> + platform_set_drvdata(pdev, wdt); >> + >> + dev_info(&pdev->dev, >> + "initialized (heartbeat = %d sec)\n", heartbeat); >> + return 0; >> + >> +err: >> + clk_disable_unprepare(clk); >> + return ret; >> +} >> + >> +static int stm32_iwdg_remove(struct platform_device *pdev) >> +{ >> + struct stm32_iwdg *wdt = platform_get_drvdata(pdev); >> + >> + watchdog_unregister_device(&wdt->wdd); >> + clk_disable_unprepare(wdt->clk); >> + >> + dev_info(&pdev->dev, "removed watchdog device\n"); > > Is this message really useful ? I think it is just noise. Ok, removed > >> + return 0; >> +} >> + >> +static const struct of_device_id stm32_iwdg_of_match[] = { >> + { .compatible = "st,stm32-iwdg" }, >> + { /* end node */ } >> +}; >> +MODULE_DEVICE_TABLE(of, stm32_iwdg_of_match); >> + >> +static struct platform_driver stm32_iwdg_driver = { >> + .probe = stm32_iwdg_probe, >> + .remove = stm32_iwdg_remove, >> + .driver = { >> + .name = "iwdg", >> + .of_match_table = stm32_iwdg_of_match, >> + }, >> +}; >> +module_platform_driver(stm32_iwdg_driver); >> + >> +MODULE_AUTHOR("Yannick Fertre <yannick.fertre@st.com>"); >> +MODULE_DESCRIPTION("STMicroelectronics STM32 Independent Watchdog >> Driver"); >> +MODULE_LICENSE("GPL v2"); >> > ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 3/5] ARM: dts: stm32: Add watchdog support for STM32F429 SoC 2017-03-22 15:04 [PATCH v3 0/5] STM32 Independant watchdog Yannick Fertre 2017-03-22 15:04 ` [PATCH v3 1/5] dt-bindings: Document STM32 IWDG bindings Yannick Fertre 2017-03-22 15:04 ` [PATCH v3 2/5] drivers: watchdog: Add STM32 IWDG driver Yannick Fertre @ 2017-03-22 15:04 ` Yannick Fertre 2017-03-22 15:04 ` [PATCH v3 4/5] ARM: dts: stm32: Add watchdog support for STM32F429 eval board Yannick Fertre ` (2 subsequent siblings) 5 siblings, 0 replies; 12+ messages in thread From: Yannick Fertre @ 2017-03-22 15:04 UTC (permalink / raw) To: Wim Van Sebroeck, Guenter Roeck, Rob Herring, Alexandre TORGUE, Benjamin Gaignard, Yannick Fertre, Maxime Coquelin Cc: linux-watchdog, linux-kernel, Philippe Cornu, Gabriel FERNANDEZ, devicetree, linux-arm-kernel Add watchdog into DT for stm32f429 family. Signed-off-by: Yannick FERTRE <yannick.fertre@st.com> --- arch/arm/boot/dts/stm32f429.dtsi | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm/boot/dts/stm32f429.dtsi b/arch/arm/boot/dts/stm32f429.dtsi index ee0da97..9b71dde 100644 --- a/arch/arm/boot/dts/stm32f429.dtsi +++ b/arch/arm/boot/dts/stm32f429.dtsi @@ -65,7 +65,7 @@ clock-frequency = <32768>; }; - clk-lsi { + clk_lsi: clk-lsi { #clock-cells = <0>; compatible = "fixed-clock"; clock-frequency = <32000>; @@ -307,6 +307,13 @@ status = "disabled"; }; + iwdg: iwdg@40003000 { + compatible = "st,stm32-iwdg"; + reg = <0x40003000 0x400>; + clocks = <&clk_lsi>; + status = "disabled"; + }; + usart2: serial@40004400 { compatible = "st,stm32-usart", "st,stm32-uart"; reg = <0x40004400 0x400>; -- 1.9.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 4/5] ARM: dts: stm32: Add watchdog support for STM32F429 eval board 2017-03-22 15:04 [PATCH v3 0/5] STM32 Independant watchdog Yannick Fertre ` (2 preceding siblings ...) 2017-03-22 15:04 ` [PATCH v3 3/5] ARM: dts: stm32: Add watchdog support for STM32F429 SoC Yannick Fertre @ 2017-03-22 15:04 ` Yannick Fertre 2017-03-22 15:04 ` [PATCH v3 5/5] ARM: configs: Add watchdog support in STM32 defconfig Yannick Fertre 2017-03-29 3:00 ` [PATCH v3 0/5] STM32 Independant watchdog Guenter Roeck 5 siblings, 0 replies; 12+ messages in thread From: Yannick Fertre @ 2017-03-22 15:04 UTC (permalink / raw) To: Wim Van Sebroeck, Guenter Roeck, Rob Herring, Alexandre TORGUE, Benjamin Gaignard, Yannick Fertre, Maxime Coquelin Cc: linux-watchdog, linux-kernel, Philippe Cornu, Gabriel FERNANDEZ, devicetree, linux-arm-kernel This patch adds watchdog support for STM32x9I-Eval board. Signed-off-by: Yannick Fertre <yannick.fertre@st.com> --- arch/arm/boot/dts/stm32429i-eval.dts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/boot/dts/stm32429i-eval.dts b/arch/arm/boot/dts/stm32429i-eval.dts index 3c99466..1c7d0b9 100644 --- a/arch/arm/boot/dts/stm32429i-eval.dts +++ b/arch/arm/boot/dts/stm32429i-eval.dts @@ -126,6 +126,10 @@ }; }; +&iwdg { + status = "okay"; +}; + &adc { pinctrl-names = "default"; pinctrl-0 = <&adc3_in8_pin>; -- 1.9.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 5/5] ARM: configs: Add watchdog support in STM32 defconfig 2017-03-22 15:04 [PATCH v3 0/5] STM32 Independant watchdog Yannick Fertre ` (3 preceding siblings ...) 2017-03-22 15:04 ` [PATCH v3 4/5] ARM: dts: stm32: Add watchdog support for STM32F429 eval board Yannick Fertre @ 2017-03-22 15:04 ` Yannick Fertre 2017-03-23 17:28 ` Alexandre Torgue 2017-03-29 3:00 ` [PATCH v3 0/5] STM32 Independant watchdog Guenter Roeck 5 siblings, 1 reply; 12+ messages in thread From: Yannick Fertre @ 2017-03-22 15:04 UTC (permalink / raw) To: Wim Van Sebroeck, Guenter Roeck, Rob Herring, Alexandre TORGUE, Benjamin Gaignard, Yannick Fertre, Maxime Coquelin Cc: linux-watchdog, linux-kernel, Philippe Cornu, Gabriel FERNANDEZ, devicetree, linux-arm-kernel This patch adds STM32 watchdog support in stm32_defconfig file Signed-off-by: Yannick Fertre <yannick.fertre@st.com> --- arch/arm/configs/stm32_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig index a9d8e3c..83afa73 100644 --- a/arch/arm/configs/stm32_defconfig +++ b/arch/arm/configs/stm32_defconfig @@ -48,6 +48,7 @@ CONFIG_SERIAL_STM32=y CONFIG_SERIAL_STM32_CONSOLE=y # CONFIG_HW_RANDOM is not set # CONFIG_HWMON is not set +CONFIG_WATCHDOG=y CONFIG_REGULATOR=y CONFIG_REGULATOR_FIXED_VOLTAGE=y # CONFIG_USB_SUPPORT is not set -- 1.9.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v3 5/5] ARM: configs: Add watchdog support in STM32 defconfig 2017-03-22 15:04 ` [PATCH v3 5/5] ARM: configs: Add watchdog support in STM32 defconfig Yannick Fertre @ 2017-03-23 17:28 ` Alexandre Torgue 0 siblings, 0 replies; 12+ messages in thread From: Alexandre Torgue @ 2017-03-23 17:28 UTC (permalink / raw) To: Yannick Fertre, Wim Van Sebroeck, Guenter Roeck, Rob Herring, Benjamin Gaignard, Maxime Coquelin Cc: linux-watchdog, linux-kernel, Philippe Cornu, Gabriel FERNANDEZ, devicetree, linux-arm-kernel Hi, On 03/22/2017 04:04 PM, Yannick Fertre wrote: > This patch adds STM32 watchdog support in stm32_defconfig file > > Signed-off-by: Yannick Fertre <yannick.fertre@st.com> > --- Update commit header please (ARM: configs: stm32: Add watchdog support) > arch/arm/configs/stm32_defconfig | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig > index a9d8e3c..83afa73 100644 > --- a/arch/arm/configs/stm32_defconfig > +++ b/arch/arm/configs/stm32_defconfig > @@ -48,6 +48,7 @@ CONFIG_SERIAL_STM32=y > CONFIG_SERIAL_STM32_CONSOLE=y > # CONFIG_HW_RANDOM is not set > # CONFIG_HWMON is not set > +CONFIG_WATCHDOG=y > CONFIG_REGULATOR=y > CONFIG_REGULATOR_FIXED_VOLTAGE=y > # CONFIG_USB_SUPPORT is not set > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 0/5] STM32 Independant watchdog 2017-03-22 15:04 [PATCH v3 0/5] STM32 Independant watchdog Yannick Fertre ` (4 preceding siblings ...) 2017-03-22 15:04 ` [PATCH v3 5/5] ARM: configs: Add watchdog support in STM32 defconfig Yannick Fertre @ 2017-03-29 3:00 ` Guenter Roeck 5 siblings, 0 replies; 12+ messages in thread From: Guenter Roeck @ 2017-03-29 3:00 UTC (permalink / raw) To: Yannick Fertre, Wim Van Sebroeck, Rob Herring, Alexandre TORGUE, Benjamin Gaignard, Maxime Coquelin Cc: linux-watchdog, linux-kernel, Philippe Cornu, Gabriel FERNANDEZ, devicetree, linux-arm-kernel Subject: s/Independant/Independent/ On 03/22/2017 08:04 AM, Yannick Fertre wrote: > Version 3: > - Update typo into bindings file > - Reorder node in devicetree (ordering by address) > - Remove unecessary lines in commits > > Version 2: > - Add commit messages > > Version 1: > - Initial commit > > The purpose of this set of patches is to add a new watchdog driver for > stm32f429. > This driver was developed and tested on evaluation board stm32429i. > > Yannick Fertre (5): > dt-bindings: Document STM32 IWDG bindings > drivers: watchdog: Add STM32 IWDG driver > ARM: dts: stm32: Add watchdog support for STM32F429 SoC > ARM: dts: stm32: Add watchdog support for STM32F429 eval board > ARM: configs: Add watchdog support in STM32 defconfig > > .../devicetree/bindings/watchdog/st,stm32-iwdg.txt | 15 ++ > arch/arm/boot/dts/stm32429i-eval.dts | 4 + > arch/arm/boot/dts/stm32f429.dtsi | 9 +- > arch/arm/configs/stm32_defconfig | 1 + > drivers/watchdog/Kconfig | 11 + > drivers/watchdog/Makefile | 1 + > drivers/watchdog/stm32_iwdg.c | 289 +++++++++++++++++++++ > 7 files changed, 329 insertions(+), 1 deletion(-) > create mode 100644 Documentation/devicetree/bindings/watchdog/st,stm32-iwdg.txt > create mode 100644 drivers/watchdog/stm32_iwdg.c > ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2017-03-30 15:12 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-03-22 15:04 [PATCH v3 0/5] STM32 Independant watchdog Yannick Fertre 2017-03-22 15:04 ` [PATCH v3 1/5] dt-bindings: Document STM32 IWDG bindings Yannick Fertre 2017-03-29 1:40 ` Rob Herring 2017-03-29 3:15 ` Guenter Roeck 2017-03-22 15:04 ` [PATCH v3 2/5] drivers: watchdog: Add STM32 IWDG driver Yannick Fertre 2017-03-29 3:15 ` Guenter Roeck 2017-03-30 15:10 ` Yannick FERTRE 2017-03-22 15:04 ` [PATCH v3 3/5] ARM: dts: stm32: Add watchdog support for STM32F429 SoC Yannick Fertre 2017-03-22 15:04 ` [PATCH v3 4/5] ARM: dts: stm32: Add watchdog support for STM32F429 eval board Yannick Fertre 2017-03-22 15:04 ` [PATCH v3 5/5] ARM: configs: Add watchdog support in STM32 defconfig Yannick Fertre 2017-03-23 17:28 ` Alexandre Torgue 2017-03-29 3:00 ` [PATCH v3 0/5] STM32 Independant watchdog Guenter Roeck
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).