From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 02/17] dm: Simple Watchdog uclass
Date: Fri, 17 Mar 2017 09:41:18 +0100 [thread overview]
Message-ID: <20170317094118.76279295@jawa> (raw)
In-Reply-To: <20170316213624.140344-3-maxims@google.com>
Hi Maxim,
> This is a simple uclass for Watchdog Timers. It has four operations:
> start, restart, reset, stop. Drivers must implement start, restart and
> stop operations, while implementing reset is optional: It's default
> implementation expires watchdog timer in one clock tick.
>
> Signed-off-by: Maxim Sloyko <maxims@google.com>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
> ---
>
> drivers/watchdog/Kconfig | 11 +++++
> drivers/watchdog/Makefile | 1 +
> drivers/watchdog/wdt-uclass.c | 79
> +++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h |
> 1 + include/wdt.h | 97
> +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 189
> insertions(+) create mode 100644 drivers/watchdog/wdt-uclass.c
> create mode 100644 include/wdt.h
>
> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> index e69de29bb2..0d7366f3df 100644
> --- a/drivers/watchdog/Kconfig
> +++ b/drivers/watchdog/Kconfig
> @@ -0,0 +1,11 @@
> +menu "Watchdog Timer Support"
> +
> +config WDT
> + bool "Enable driver model for watchdog timer drivers"
> + depends on DM
> + help
> + Enable driver model for watchdog timer. At the moment the
> API
> + is very simple and only supports four operations:
> + start, restart, stop and reset (expire immediately).
> + What exactly happens when the timer expires is up to a
> particular
> + device/driver.
> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> index a007ae8234..1aabcb97ae 100644
> --- a/drivers/watchdog/Makefile
> +++ b/drivers/watchdog/Makefile
> @@ -15,3 +15,4 @@ obj-$(CONFIG_XILINX_TB_WATCHDOG) += xilinx_tb_wdt.o
> obj-$(CONFIG_BFIN_WATCHDOG) += bfin_wdt.o
> obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
> obj-$(CONFIG_DESIGNWARE_WATCHDOG) += designware_wdt.o
> +obj-$(CONFIG_WDT) += wdt-uclass.o
> diff --git a/drivers/watchdog/wdt-uclass.c
> b/drivers/watchdog/wdt-uclass.c new file mode 100644
> index 0000000000..98a8b529f9
> --- /dev/null
> +++ b/drivers/watchdog/wdt-uclass.c
> @@ -0,0 +1,79 @@
> +/*
> + * Copyright 2017 Google, Inc
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <errno.h>
> +#include <wdt.h>
> +#include <dm/lists.h>
> +#include <dm/device-internal.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +/*
> + * Implement a simple watchdog uclass. Watchdog is basically a timer
> that
> + * is used to detect or recover from malfunction. During normal
> operation
> + * the watchdog would be regularly reset to prevent it from timing
> out.
> + * If, due to a hardware fault or program error, the computer fails
> to reset
> + * the watchdog, the timer will elapse and generate a timeout signal.
> + * The timeout signal is used to initiate corrective action or
> actions,
> + * which typically include placing the system in a safe, known state.
> + */
> +
> +int wdt_start(struct udevice *dev, u64 timeout, ulong flags)
> +{
> + const struct wdt_ops *ops = device_get_ops(dev);
> +
> + if (!ops->start)
> + return -ENOSYS;
> +
> + return ops->start(dev, timeout, flags);
> +}
> +
> +int wdt_stop(struct udevice *dev)
> +{
> + const struct wdt_ops *ops = device_get_ops(dev);
> +
> + if (!ops->stop)
> + return -ENOSYS;
> +
> + return ops->stop(dev);
> +}
> +
> +int wdt_restart(struct udevice *dev)
> +{
> + const struct wdt_ops *ops = device_get_ops(dev);
> +
> + if (!ops->restart)
> + return -ENOSYS;
> +
> + return ops->restart(dev);
> +}
> +
> +int wdt_reset(struct udevice *dev, ulong flags)
> +{
> + const struct wdt_ops *ops;
> +
> + debug("WDT Resettting: %lu\n", flags);
> + ops = device_get_ops(dev);
> + if (ops->reset) {
> + return ops->reset(dev, flags);
> + } else {
> + if (!ops->start)
> + return -ENOSYS;
> +
> + ops->start(dev, 1, flags);
> + while (1)
> + ;
> + }
> +
> + return 0;
> +}
> +
> +UCLASS_DRIVER(wdt) = {
> + .id = UCLASS_WDT,
> + .name = "wdt",
> +};
> diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
> index 8c92d0b030..b73a7fd436 100644
> --- a/include/dm/uclass-id.h
> +++ b/include/dm/uclass-id.h
> @@ -83,6 +83,7 @@ enum uclass_id {
> UCLASS_VIDEO, /* Video or LCD device */
> UCLASS_VIDEO_BRIDGE, /* Video bridge, e.g.
> DisplayPort to LVDS */ UCLASS_VIDEO_CONSOLE, /* Text console
> driver for video device */
> + UCLASS_WDT, /* Watchdot Timer driver */
>
> UCLASS_COUNT,
> UCLASS_INVALID = -1,
> diff --git a/include/wdt.h b/include/wdt.h
> new file mode 100644
> index 0000000000..1da5a962df
> --- /dev/null
> +++ b/include/wdt.h
> @@ -0,0 +1,97 @@
> +/*
> + * Copyright 2017 Google, Inc
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +#ifndef _WDT_H_
> +#define _WDT_H_
> +
> +/*
> + * Start the timer
> + *
> + * @dev: WDT Device
> + * @timeout: Number of ticks before timer expires
> + * @flags: Driver specific flags. This might be used to specify
> + * which action needs to be executed when the timer expires
> + * @return: 0 if OK, -ve on error
> + */
> +int wdt_start(struct udevice *dev, u64 timeout, ulong flags);
> +
> +/*
> + * Stop the timer
> + *
> + * @dev: WDT Device
> + * @return: 0 if OK, -ve on error
> + */
> +int wdt_stop(struct udevice *dev);
> +
> +/*
> + * Restart the timer, typically restoring the counter to
> + * the value configured by start()
> + *
> + * @dev: WDT Device
> + * @return: 0 if OK, -ve on error
> + */
> +int wdt_restart(struct udevice *dev);
> +
> +/*
> + * Expire the timer, thus executing its action immediately
> + *
> + * Will either use chosen wdt, based on reset-wdt
> + * chosen property, or the first one available.
> + *
> + * @flags: Driver specific flags
> + * @return 0 if OK -ve on error. If wdt action is system reset,
> + * this function may never return.
> + */
> +int wdt_reset(struct udevice *dev, ulong flags);
> +
> +/*
> + * struct wdt_ops - Driver model wdt operations
> + *
> + * The uclass interface is implemented by all wdt devices which use
> + * driver model.
> + */
> +struct wdt_ops {
> + /*
> + * Start the timer
> + *
> + * @dev: WDT Device
> + * @timeout: Number of ticks before the timer expires
> + * @flags: Driver specific flags. This might be used to
> specify
> + * which action needs to be executed when the timer expires
> + * @return: 0 if OK, -ve on error
> + */
> + int (*start)(struct udevice *dev, u64 timeout, ulong flags);
> + /*
> + * Stop the timer
> + *
> + * @dev: WDT Device
> + * @return: 0 if OK, -ve on error
> + */
> + int (*stop)(struct udevice *dev);
> + /*
> + * Restart the timer, typically restoring the counter to
> + * the value configured by start()
> + *
> + * @dev: WDT Device
> + * @return: 0 if OK, -ve on error
> + */
> + int (*restart)(struct udevice *dev);
> + /*
> + * Expire the timer, thus executing the action immediately
> (optional)
> + *
> + * If this function is not provided, default implementation
> + * will be used for wdt_reset(), which is set the counter to
> 1
> + * and wait forever. This is good enough for system level
> + * reset, but not good enough for resetting peripherals.
> + *
> + * @dev: WDT Device
> + * @flags: Driver specific flags
> + * @return 0 if OK -ve on error. May not return.
> + */
> + int (*reset)(struct udevice *dev, ulong flags);
> +};
> +
> +#endif /* _WDT_H_ */
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
next prev parent reply other threads:[~2017-03-17 8:41 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-16 21:36 [U-Boot] [PATCH 00/17] Expand Aspeed AST2500 Support Maxim Sloyko
2017-03-16 21:36 ` [U-Boot] [PATCH 01/17] aspeed: Update ast2500 Device Tree Maxim Sloyko
2017-03-21 23:21 ` Simon Glass
2017-03-16 21:36 ` [U-Boot] [PATCH 02/17] dm: Simple Watchdog uclass Maxim Sloyko
2017-03-17 8:41 ` Lukasz Majewski [this message]
2017-03-21 23:22 ` Simon Glass
2017-03-16 21:36 ` [U-Boot] [PATCH 03/17] aspeed: Watchdog Timer Driver Maxim Sloyko
2017-03-21 23:22 ` Simon Glass
2017-03-16 21:36 ` [U-Boot] [PATCH 04/17] aspeed: Make SCU lock/unlock functions part of SCU API Maxim Sloyko
2017-03-21 23:22 ` Simon Glass
2017-03-16 21:36 ` [U-Boot] [PATCH 05/17] aspeed: Reset Driver Maxim Sloyko
2017-03-21 23:22 ` Simon Glass
2017-03-24 0:50 ` Maxim Sloyko
2017-03-16 21:36 ` [U-Boot] [PATCH 06/17] aspeed: Device Tree configuration for " Maxim Sloyko
2017-03-21 23:22 ` Simon Glass
2017-03-16 21:36 ` [U-Boot] [PATCH 07/17] aspeed: Refactor AST2500 RAM Driver and Sysreset Driver Maxim Sloyko
2017-03-21 23:22 ` Simon Glass
2017-03-16 21:36 ` [U-Boot] [PATCH 08/17] aspeed: AST2500 Pinctrl Driver Maxim Sloyko
2017-03-21 23:22 ` Simon Glass
2017-03-16 21:36 ` [U-Boot] [PATCH 09/17] aspeed: Enable Pinctrl Driver in AST2500 EVB Maxim Sloyko
2017-03-21 23:22 ` Simon Glass
2017-03-16 21:36 ` [U-Boot] [PATCH 10/17] aspeed: Add P-Bus clock in ast2500 clock driver Maxim Sloyko
2017-03-21 23:22 ` Simon Glass
2017-03-16 21:36 ` [U-Boot] [PATCH 11/17] aspeed: Add I2C Driver Maxim Sloyko
2017-03-20 6:35 ` Heiko Schocher
2017-03-22 13:05 ` Simon Glass
2017-03-27 10:40 ` Benjamin Herrenschmidt
2017-03-27 10:41 ` Benjamin Herrenschmidt
2017-03-16 21:36 ` [U-Boot] [PATCH 12/17] aspeed: Enable I2C in EVB defconfig Maxim Sloyko
2017-03-21 23:22 ` Simon Glass
2017-03-16 21:36 ` [U-Boot] [PATCH 13/17] aspeed: Add support for Clocks needed by MACs Maxim Sloyko
2017-03-19 16:42 ` Tom Rini
2017-03-20 17:24 ` Maxim Sloyko
2017-03-20 17:30 ` Tom Rini
2017-03-20 17:52 ` Maxim Sloyko
2017-03-20 19:48 ` Tom Rini
2017-03-20 22:36 ` Maxim Sloyko
2017-03-20 20:43 ` Rick Altherr
2017-03-21 1:18 ` Joel Stanley
2017-03-16 21:36 ` [U-Boot] [PATCH 14/17] aspeed: Refactor SCU to use consistent mask & shift Maxim Sloyko
2017-03-21 23:22 ` Simon Glass
2017-03-16 21:36 ` [U-Boot] [PATCH 15/17] aspeed: Cleanup ast2500-u-boot.dtsi Device Tree Maxim Sloyko
2017-03-16 21:36 ` [U-Boot] [PATCH 16/17] aspeed: Add AST2500/AST2400 compatible NIC Driver Maxim Sloyko
2017-03-21 19:32 ` Joe Hershberger
2017-03-21 23:44 ` Maxim Sloyko
2017-03-22 13:06 ` Simon Glass
2017-03-24 0:42 ` Maxim Sloyko
2017-03-16 21:36 ` [U-Boot] [PATCH 17/17] aspeed: Network Driver configuration for EVB Maxim Sloyko
2017-03-21 23:22 ` Simon Glass
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=20170317094118.76279295@jawa \
--to=lukma@denx.de \
--cc=u-boot@lists.denx.de \
/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