watchdog: add amlogic watchdog support
Subsystems (2)
PATCH 1/1 watchdog: add amlogic watchdog support
Add support for hardware watchdog timer for Amlogic SoCs. This driver has been heavily inspired by his Linux equivalent (meson_gxbb_wdt.c).
---
This watchdog driver has been tested on a GXL libretech-cc board and also on a custom G12a board. I did the following test cases:
* boot with a faulty boot command, then we reach watchdog reset successfully,
* boot a Linux kernel with and without watchdog support, and check if it is working as expected.
drivers/watchdog/Kconfig | 6 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/meson_gxbb_wdt.c | 126 ++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 drivers/watchdog/meson_gxbb_wdt.c
drivers/watchdog/Kconfig +6 -0
@@ -175,6 +175,12 @@ config WDT_MAX6370 help Select this to enable max6370 watchdog timer. +config WDT_MESON_GXBB + bool "Amlogic watchdog timer support" + depends on WDT + help + Amlogic watchdog timer support. + config WDT_MPC8xx bool "MPC8xx watchdog timer support" depends on WDT && MPC8xx
drivers/watchdog/Makefile +1 -0
@@ -27,6 +27,7 @@ obj-$(CONFIG_WDT_ORION) += orion_wdt.o obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o obj-$(CONFIG_WDT_GPIO) += gpio_wdt.o obj-$(CONFIG_WDT_MAX6370) += max6370_wdt.o +obj-$(CONFIG_WDT_MESON_GXBB) += meson_gxbb_wdt.o obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o obj-$(CONFIG_WDT_MT7620) += mt7620_wdt.o obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.o
drivers/watchdog/meson_gxbb_wdt.c new file +126 -0
126 lines not on this page · raw message
Signature · 1 line
2.20.1
Quoted 172 lines · Philippe Boos
Add support for hardware watchdog timer for Amlogic SoCs. This driver has been heavily inspired by his Linux equivalent (
meson_gxbb_wdt.c).Reviewed-by Jerome Brunet <[email protected]>Signed-off-by Philippe Boos <[email protected]>---
This watchdog driver has been tested on a GXL libretech-cc board and also on a custom G12a board. I did the following test cases:
* boot with a faulty boot command, then we reach watchdog reset successfully,
* boot a Linux kernel with and without watchdog support, and check if it is working as expected.drivers/watchdog/Kconfig | 6 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/meson_gxbb_wdt.c | 126 ++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+)create mode 100644
drivers/watchdog/meson_gxbb_wdt.cdrivers/watchdog/Kconfig +6
-0@@ -175,6 +175,12 @@ config WDT_MAX6370 help Select this to enable max6370 watchdog timer. +config WDT_MESON_GXBB + bool "Amlogic watchdog timer support" + depends on WDT + help + Amlogic watchdog timer support. + config WDT_MPC8xx bool "MPC8xx watchdog timer support" depends on WDT && MPC8xxdrivers/watchdog/Makefile +1
-0@@ -27,6 +27,7 @@ obj-$(CONFIG_WDT_ORION) += orion_wdt.o obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o obj-$(CONFIG_WDT_GPIO) += gpio_wdt.o obj-$(CONFIG_WDT_MAX6370) += max6370_wdt.o +obj-$(CONFIG_WDT_MESON_GXBB) += meson_gxbb_wdt.o obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o obj-$(CONFIG_WDT_MT7620) += mt7620_wdt.o obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.odrivers/watchdog/meson_gxbb_wdt.c new file +116
-0@@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (c) 2022 BayLibre, SAS. +*/ + +#include <clk.h> +#include <common.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <reset.h> +#include <wdt.h> +#include <asm/io.h> +#include <linux/bitops.h> + +#define GXBB_WDT_CTRL_REG 0x0 +#define GXBB_WDT_TCNT_REG 0x8 +#define GXBB_WDT_RSET_REG 0xc + +#define GXBB_WDT_CTRL_CLKDIV_EN BIT(25) +#define GXBB_WDT_CTRL_CLK_EN BIT(24) +#define GXBB_WDT_CTRL_EE_RESET BIT(21) +#define GXBB_WDT_CTRL_EN BIT(18) + +#define GXBB_WDT_CTRL_DIV_MASK GENMASK(17, 0) +#define GXBB_WDT_TCNT_SETUP_MASK GENMASK(15, 0) + + +struct amlogic_wdt_priv { +void __iomem *reg_base; +}; + +static int amlogic_wdt_set_timeout (struct udevice *dev,u64 timeout_ms) +{ +struct amlogic_wdt_priv *data =dev_get_priv (dev); + +if (timeout_ms >GXBB_WDT_TCNT_SETUP_MASK ) { +dev_warn (dev,"%s: timeout_ms=%llu: maximum watchdog timeout " +"exceeded\n" , __func__, timeout_ms); + timeout_ms =GXBB_WDT_TCNT_SETUP_MASK ; + } + +writel (timeout_ms, data->reg_base +GXBB_WDT_TCNT_REG ); + +return 0 ; +} + +static int amlogic_wdt_stop (struct udevice *dev) +{ +struct amlogic_wdt_priv *data =dev_get_priv (dev); + +writel (readl (data->reg_base +GXBB_WDT_CTRL_REG ) & ~GXBB_WDT_CTRL_EN , + data->reg_base +GXBB_WDT_CTRL_REG ); + +return 0 ; +} + +static int amlogic_wdt_start (struct udevice *dev,u64 time_ms,ulong flags) +{ +struct amlogic_wdt_priv *data =dev_get_priv (dev); + +writel (readl (data->reg_base +GXBB_WDT_CTRL_REG ) |GXBB_WDT_CTRL_EN , + data->reg_base +GXBB_WDT_CTRL_REG ); + +return amlogic_wdt_set_timeout (dev, time_ms); +} + +static int amlogic_wdt_reset (struct udevice *dev) +{ +struct amlogic_wdt_priv *data =dev_get_priv (dev); + +writel (0 , data->reg_base +GXBB_WDT_RSET_REG ); + +return 0 ; +} + +static int amlogic_wdt_probe (struct udevice *dev) +{ +struct amlogic_wdt_priv *data =dev_get_priv (dev); +int ret; + + data->reg_base =dev_remap_addr (dev); +if (!data->reg_base) +return -EINVAL ; + +struct clk clk; + + ret =clk_get_by_index (dev,0 , &clk); +if (ret) +return ret; + + ret =clk_enable (&clk); +if (ret) { +clk_free (&clk); +return ret; + } + +/* Setup with 1ms timebase */ +writel (((clk_get_rate (&clk) /1000 ) &GXBB_WDT_CTRL_DIV_MASK ) | +GXBB_WDT_CTRL_EE_RESET | +GXBB_WDT_CTRL_CLK_EN | +GXBB_WDT_CTRL_CLKDIV_EN , + data->reg_base +GXBB_WDT_CTRL_REG ); + +return 0 ; +} + +static const struct wdt_ops amlogic_wdt_ops = { + .start = amlogic_wdt_start, + .reset = amlogic_wdt_reset, + .stop = amlogic_wdt_stop, +}; + +static const struct udevice_id amlogic_wdt_ids[] = { + { .compatible ="amlogic,meson-gxbb-wdt" }, + {} +};
drivers/watchdog/meson_gxbb_wdt.c line 126
Quoted 10 lines
drivers/watchdog/meson_gxbb_wdt.c new file +10
-0+ +U_BOOT_DRIVER (amlogic_wdt) = { + .name ="amlogic_wdt" , + .id =UCLASS_WDT , + .of_match = amlogic_wdt_ids, + .priv_auto =sizeof (struct amlogic_wdt_priv ), + .probe = amlogic_wdt_probe, + .ops = &amlogic_wdt_ops, + .flags =DM_FLAG_PRE_RELOC , +};
Can you update MAINTAINERS to include it in "ARM AMLOGIC SOC SUPPORT" entry ?
With this:
Thanks,
Neil
Quoted 185 lines · Neil Armstrong
Quoted 171 lines · Philippe Boos
Add support for hardware watchdog timer for Amlogic SoCs. This driver has been heavily inspired by his Linux equivalent (
meson_gxbb_wdt.c).Reviewed-by Jerome Brunet <[email protected]>Signed-off-by Philippe Boos <[email protected]>---
This watchdog driver has been tested on a GXL libretech-cc board and also on a custom G12a board. I did the following test cases:
* boot with a faulty boot command, then we reach watchdog reset successfully,
* boot a Linux kernel with and without watchdog support, and check if it is working as expected.drivers/watchdog/Kconfig | 6 ++ drivers/watchdog/Makefile | 1 +
drivers/watchdog/meson_gxbb_wdt.c| 126 ++++++++++++++++++++++++++++++3 files changed, 133 insertions(+)create mode 100644
drivers/watchdog/meson_gxbb_wdt.cdrivers/watchdog/Kconfig +0
-0@@ -175,6 +175,12 @@ config WDT_MAX6370help
Select this to enable max6370 watchdog timer.drivers/watchdog/Kconfig +6
-0+config WDT_MESON_GXBB + bool "Amlogic watchdog timer support" + depends on WDT + help + Amlogic watchdog timer support. +config
WDT_MPC8xx
bool "MPC8xx watchdog timer support"
depends on WDT && MPC8xxdrivers/watchdog/Makefile +0
-0@@ -27,6 +27,7 @@ obj-$(CONFIG_WDT_ORION) += orion_wdt.oobj-$(CONFIG_WDT_CDNS) += cdns_wdt.o
obj-$(CONFIG_WDT_GPIO) += gpio_wdt.o
obj-$(CONFIG_WDT_MAX6370) += max6370_wdt.o
+obj-$(CONFIG_WDT_MESON_GXBB) += meson_gxbb_wdt.o
obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o
obj-$(CONFIG_WDT_MT7620) += mt7620_wdt.o
obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.odrivers/watchdog/meson_gxbb_wdt.c new file +116
-0@@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (c) 2022 BayLibre, SAS. +*/ + +#include <clk.h> +#include <common.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <reset.h> +#include <wdt.h> +#include <asm/io.h> +#include <linux/bitops.h> + +#define GXBB_WDT_CTRL_REG 0x0 +#define GXBB_WDT_TCNT_REG 0x8 +#define GXBB_WDT_RSET_REG 0xc + +#define GXBB_WDT_CTRL_CLKDIV_EN BIT(25) +#define GXBB_WDT_CTRL_CLK_EN BIT(24) +#define GXBB_WDT_CTRL_EE_RESET BIT(21) +#define GXBB_WDT_CTRL_EN BIT(18) + +#define GXBB_WDT_CTRL_DIV_MASK GENMASK(17, 0) +#define GXBB_WDT_TCNT_SETUP_MASK GENMASK(15, 0) + + +struct amlogic_wdt_priv { + void __iomem *reg_base; +}; + +static int amlogic_wdt_set_timeout (struct udevice *dev,u64 timeout_ms) +{ + struct amlogic_wdt_priv *data = dev_get_priv(dev); + + if (timeout_ms > GXBB_WDT_TCNT_SETUP_MASK) { + dev_warn(dev, "%s: timeout_ms=%llu: maximum watchdog timeout " + "exceeded\n", __func__, timeout_ms); + timeout_ms = GXBB_WDT_TCNT_SETUP_MASK; + } + + writel(timeout_ms, data->reg_base + GXBB_WDT_TCNT_REG); + + return 0; +} + +static int amlogic_wdt_stop (struct udevice *dev) +{ + struct amlogic_wdt_priv *data = dev_get_priv(dev); + + writel(readl(data->reg_base + GXBB_WDT_CTRL_REG) & ~GXBB_WDT_CTRL_EN, + data->reg_base + GXBB_WDT_CTRL_REG); + + return 0; +} + +static int amlogic_wdt_start (struct udevice *dev,u64 time_ms,ulong flags) +{ + struct amlogic_wdt_priv *data = dev_get_priv(dev); + + writel(readl(data->reg_base + GXBB_WDT_CTRL_REG) | GXBB_WDT_CTRL_EN, + data->reg_base + GXBB_WDT_CTRL_REG); + + return amlogic_wdt_set_timeout(dev, time_ms); +} + +static int amlogic_wdt_reset (struct udevice *dev) +{ + struct amlogic_wdt_priv *data = dev_get_priv(dev); + + writel(0, data->reg_base + GXBB_WDT_RSET_REG); + + return 0; +} + +static int amlogic_wdt_probe (struct udevice *dev) +{ + struct amlogic_wdt_priv *data = dev_get_priv(dev); + int ret; + + data->reg_base = dev_remap_addr(dev); + if (!data->reg_base) + return -EINVAL; + + struct clk clk; + + ret = clk_get_by_index(dev, 0, &clk); + if (ret) + return ret; + + ret = clk_enable(&clk); + if (ret) { + clk_free(&clk); + return ret; + } + + /* Setup with 1ms timebase */ + writel(((clk_get_rate(&clk) / 1000) & GXBB_WDT_CTRL_DIV_MASK) | + GXBB_WDT_CTRL_EE_RESET | + GXBB_WDT_CTRL_CLK_EN | + GXBB_WDT_CTRL_CLKDIV_EN, + data->reg_base + GXBB_WDT_CTRL_REG); + + return 0; +} + +static const struct wdt_ops amlogic_wdt_ops = { + .start = amlogic_wdt_start, + .reset = amlogic_wdt_reset, + .stop = amlogic_wdt_stop, +}; + +static const struct udevice_id amlogic_wdt_ids[] = { + { .compatible = "amlogic,meson-gxbb-wdt" }, + {} +};drivers/watchdog/meson_gxbb_wdt.c line 126
Quoted 10 lines
drivers/watchdog/meson_gxbb_wdt.c new file +10
-0+ +U_BOOT_DRIVER (amlogic_wdt) = { + .name = "amlogic_wdt", + .id = UCLASS_WDT, + .of_match = amlogic_wdt_ids, + .priv_auto = sizeof(struct amlogic_wdt_priv), + .probe = amlogic_wdt_probe, + .ops = &amlogic_wdt_ops, + .flags = DM_FLAG_PRE_RELOC, +};Can you update
MAINTAINERSto include it in "ARM AMLOGIC SOC SUPPORT" entry ?
Quoted 2 lines
With this:
Reviewed-by Neil Armstrong <[email protected]>
Adding an entry in the support matrix would be also great !
(see doc/board/amlogic/index.rst)
Thanks,
Neil
Quoted 3 lines
Thanks,
Neil
Quoted 26 lines · Philippe Boos
Add support for hardware watchdog timer for Amlogic SoCs. This driver has been heavily inspired by his Linux equivalent (
meson_gxbb_wdt.c).Reviewed-by Jerome Brunet <[email protected]>Signed-off-by Philippe Boos <[email protected]>---
This watchdog driver has been tested on a GXL libretech-cc board and also on a custom G12a board. I did the following test cases:
* boot with a faulty boot command, then we reach watchdog reset successfully,
* boot a Linux kernel with and without watchdog support, and check if it is working as expected.drivers/watchdog/Kconfig | 6 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/meson_gxbb_wdt.c | 126 ++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+)create mode 100644
drivers/watchdog/meson_gxbb_wdt.cdrivers/watchdog/Kconfig +0
-0
drivers/watchdog/Kconfig config WDT_MAX6370 · line 183
Quoted 9 lines
drivers/watchdog/Kconfig +6
-0@@ -175,6 +175,12 @@ config WDT_MAX6370 help Select this to enable max6370 watchdog timer. +config WDT_MESON_GXBB + bool "Amlogic watchdog timer support" + depends on WDT + help + Amlogic watchdog timer support. +
This description / help text is a bit short. Could you please extend this at least a bit in v2?
Quoted 21 lines
drivers/watchdog/Kconfig +0
-0config WDT_MPC8xx bool "MPC8xx watchdog timer support" depends on WDT && MPC8xxdrivers/watchdog/Makefile +1
-0@@ -27,6 +27,7 @@ obj-$(CONFIG_WDT_ORION) += orion_wdt.o obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o obj-$(CONFIG_WDT_GPIO) += gpio_wdt.o obj-$(CONFIG_WDT_MAX6370) += max6370_wdt.o +obj-$(CONFIG_WDT_MESON_GXBB) += meson_gxbb_wdt.o obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o obj-$(CONFIG_WDT_MT7620) += mt7620_wdt.o obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.odrivers/watchdog/meson_gxbb_wdt.c new file +0
-0
drivers/watchdog/meson_gxbb_wdt.c line 7
Quoted 7 lines
drivers/watchdog/meson_gxbb_wdt.c new file +7
-0@@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (c) 2022 BayLibre, SAS. +*/ + +#include <clk.h> +#include <common.h>
It's not recommended to included "common.h" in general any more. Please try to drop it.
Quoted 21 lines
drivers/watchdog/meson_gxbb_wdt.c new file +21
-0+#include <dm.h> +#include <dm/device_compat.h> +#include <reset.h> +#include <wdt.h> +#include <asm/io.h> +#include <linux/bitops.h> + +#define GXBB_WDT_CTRL_REG 0x0 +#define GXBB_WDT_TCNT_REG 0x8 +#define GXBB_WDT_RSET_REG 0xc + +#define GXBB_WDT_CTRL_CLKDIV_EN BIT(25) +#define GXBB_WDT_CTRL_CLK_EN BIT(24) +#define GXBB_WDT_CTRL_EE_RESET BIT(21) +#define GXBB_WDT_CTRL_EN BIT(18) + +#define GXBB_WDT_CTRL_DIV_MASK GENMASK(17, 0) +#define GXBB_WDT_TCNT_SETUP_MASK GENMASK(15, 0) + + +struct amlogic_wdt_priv {
drivers/watchdog/meson_gxbb_wdt.c line 38
Quoted 10 lines
drivers/watchdog/meson_gxbb_wdt.c new file +10
-0+void __iomem *reg_base; +}; + +static int amlogic_wdt_set_timeout (struct udevice *dev,u64 timeout_ms) +{ +struct amlogic_wdt_priv *data =dev_get_priv (dev); + +if (timeout_ms >GXBB_WDT_TCNT_SETUP_MASK ) { +dev_warn (dev,"%s: timeout_ms=%llu: maximum watchdog timeout " +"exceeded\n" , __func__, timeout_ms);
Splitting strings should not be done. Better have an over long line instead. checkpatch.pl should help here.
Quoted 62 lines
drivers/watchdog/meson_gxbb_wdt.c new file +62
-0+ timeout_ms =GXBB_WDT_TCNT_SETUP_MASK ; + } + +writel (timeout_ms, data->reg_base +GXBB_WDT_TCNT_REG ); + +return 0 ; +} + +static int amlogic_wdt_stop (struct udevice *dev) +{ +struct amlogic_wdt_priv *data =dev_get_priv (dev); + +writel (readl (data->reg_base +GXBB_WDT_CTRL_REG ) & ~GXBB_WDT_CTRL_EN , + data->reg_base +GXBB_WDT_CTRL_REG ); + +return 0 ; +} + +static int amlogic_wdt_start (struct udevice *dev,u64 time_ms,ulong flags) +{ +struct amlogic_wdt_priv *data =dev_get_priv (dev); + +writel (readl (data->reg_base +GXBB_WDT_CTRL_REG ) |GXBB_WDT_CTRL_EN , + data->reg_base +GXBB_WDT_CTRL_REG ); + +return amlogic_wdt_set_timeout (dev, time_ms); +} + +static int amlogic_wdt_reset (struct udevice *dev) +{ +struct amlogic_wdt_priv *data =dev_get_priv (dev); + +writel (0 , data->reg_base +GXBB_WDT_RSET_REG ); + +return 0 ; +} + +static int amlogic_wdt_probe (struct udevice *dev) +{ +struct amlogic_wdt_priv *data =dev_get_priv (dev); +int ret; + + data->reg_base =dev_remap_addr (dev); +if (!data->reg_base) +return -EINVAL ; + +struct clk clk; + + ret =clk_get_by_index (dev,0 , &clk); +if (ret) +return ret; + + ret =clk_enable (&clk); +if (ret) { +clk_free (&clk); +return ret; + } + +/* Setup with 1ms timebase */ + writel(((clk_get_rate(&clk) / 1000) & GXBB_WDT_CTRL_DIV_MASK) | + GXBB_WDT_CTRL_EE_RESET | + GXBB_WDT_CTRL_CLK_EN |
drivers/watchdog/meson_gxbb_wdt.c line 110
Quoted 10 lines
drivers/watchdog/meson_gxbb_wdt.c new file +10
-0+GXBB_WDT_CTRL_CLKDIV_EN , + data->reg_base + GXBB_WDT_CTRL_REG); + +return 0 ; +} + +static const struct wdt_ops amlogic_wdt_ops = { + .start = amlogic_wdt_start, + .reset = amlogic_wdt_reset, + .stop = amlogic_wdt_stop,
Could you perhaps also add an "expire_now" entry? This is handy for testing via the "wdt" cmd.
Looks good otherwise.
Thanks,
Stefan
Quoted 6 lines
drivers/watchdog/meson_gxbb_wdt.c new file +6
-0+}; + +static const struct udevice_id amlogic_wdt_ids[] = { + { .compatible ="amlogic,meson-gxbb-wdt" }, + {} +};
drivers/watchdog/meson_gxbb_wdt.c line 126
Quoted 10 lines
drivers/watchdog/meson_gxbb_wdt.c new file +10
-0+ +U_BOOT_DRIVER (amlogic_wdt) = { + .name ="amlogic_wdt" , + .id =UCLASS_WDT , + .of_match = amlogic_wdt_ids, + .priv_auto =sizeof (struct amlogic_wdt_priv ), + .probe = amlogic_wdt_probe, + .ops = &amlogic_wdt_ops, + .flags =DM_FLAG_PRE_RELOC , +};
Viele Grüße,
Stefan Roese
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]