linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Romain Perier <romain.perier@gmail.com>
Cc: Wim Van Sebroeck <wim@linux-watchdog.org>,
	Rob Herring <robh+dt@kernel.org>, Daniel Palmer <daniel@0x0f.com>,
	Mohammed Billoo <mohammed.billoo@gmail.com>,
	linux-watchdog@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/3] watchdog: Add Mstar MSC313e WDT driver
Date: Sat, 5 Jun 2021 13:26:49 -0700	[thread overview]
Message-ID: <20210605202649.GA286016@roeck-us.net> (raw)
In-Reply-To: <20210605170441.33667-3-romain.perier@gmail.com>

On Sat, Jun 05, 2021 at 07:04:40PM +0200, Romain Perier wrote:
> From: Daniel Palmer <daniel@0x0f.com>
> 
> It adds a driver for the IP block handling the watchdog timer found for
> Mstar MSC313e SoCs and newer.
> 
> Signed-off-by: Daniel Palmer <daniel@0x0f.com>
> Co-developed-by: Romain Perier <romain.perier@gmail.com>
> Signed-off-by: Romain Perier <romain.perier@gmail.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  MAINTAINERS                    |   1 +
>  drivers/watchdog/Kconfig       |  12 +++
>  drivers/watchdog/Makefile      |   1 +
>  drivers/watchdog/msc313e_wdt.c | 166 +++++++++++++++++++++++++++++++++
>  4 files changed, 180 insertions(+)
>  create mode 100644 drivers/watchdog/msc313e_wdt.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index a0f37adb9e64..fcc10c57298c 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2177,6 +2177,7 @@ F:	arch/arm/mach-mstar/
>  F:	drivers/clk/mstar/
>  F:	drivers/gpio/gpio-msc313.c
>  F:	drivers/pinctrl/pinctrl-msc313.c
> +F:	drivers/watchdog/msc313e_wdt.c
>  F:	include/dt-bindings/clock/mstar-*
>  F:	include/dt-bindings/gpio/msc313-gpio.h
>  F:	include/soc/mstar/
> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> index 355100dad60a..4af84df1ce22 100644
> --- a/drivers/watchdog/Kconfig
> +++ b/drivers/watchdog/Kconfig
> @@ -980,6 +980,18 @@ config VISCONTI_WATCHDOG
>  	  Say Y here to include support for the watchdog timer in Toshiba
>  	  Visconti SoCs.
>  
> +config MSC313E_WATCHDOG
> +	tristate "MStar MSC313e watchdog"
> +	depends on ARCH_MSTARV7 || COMPILE_TEST
> +	select WATCHDOG_CORE
> +	help
> +	  Say Y here to include support for the Watchdog timer embedded
> +	  into MStar MSC313e chips. This will reboot your system when the
> +	  timeout is reached.
> +
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called msc313e_wdt.
> +
>  # X86 (i386 + ia64 + x86_64) Architecture
>  
>  config ACQUIRE_WDT
> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> index a7eade8b4d45..7fa392ae3000 100644
> --- a/drivers/watchdog/Makefile
> +++ b/drivers/watchdog/Makefile
> @@ -92,6 +92,7 @@ obj-$(CONFIG_SPRD_WATCHDOG) += sprd_wdt.o
>  obj-$(CONFIG_PM8916_WATCHDOG) += pm8916_wdt.o
>  obj-$(CONFIG_ARM_SMC_WATCHDOG) += arm_smc_wdt.o
>  obj-$(CONFIG_VISCONTI_WATCHDOG) += visconti_wdt.o
> +obj-$(CONFIG_MSC313E_WATCHDOG) += msc313e_wdt.o
>  
>  # X86 (i386 + ia64 + x86_64) Architecture
>  obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
> diff --git a/drivers/watchdog/msc313e_wdt.c b/drivers/watchdog/msc313e_wdt.c
> new file mode 100644
> index 000000000000..0d497aa0fb7d
> --- /dev/null
> +++ b/drivers/watchdog/msc313e_wdt.c
> @@ -0,0 +1,166 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * MStar WDT driver
> + *
> + * Copyright (C) 2019 - 2021 Daniel Palmer
> + * Copyright (C) 2021 Romain Perier
> + *
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/io.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/watchdog.h>
> +
> +#define REG_WDT_CLR			0x0
> +#define REG_WDT_MAX_PRD_L		0x10
> +#define REG_WDT_MAX_PRD_H		0x14
> +
> +#define MSC313E_WDT_MIN_TIMEOUT		1
> +#define MSC313E_WDT_DEFAULT_TIMEOUT	30
> +
> +static unsigned int timeout;
> +
> +module_param(timeout, int, 0);
> +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds");
> +
> +struct msc313e_wdt_priv {
> +	void __iomem *base;
> +	struct watchdog_device wdev;
> +	struct clk *clk;
> +};
> +
> +static int msc313e_wdt_start(struct watchdog_device *wdev)
> +{
> +	struct msc313e_wdt_priv *priv = watchdog_get_drvdata(wdev);
> +	u32 timeout;
> +	int err;
> +
> +	err = clk_prepare_enable(priv->clk);
> +	if (err)
> +		return err;
> +
> +	timeout = wdev->timeout * clk_get_rate(priv->clk);
> +	writew(timeout & 0xffff, priv->base + REG_WDT_MAX_PRD_L);
> +	writew((timeout >> 16) & 0xffff, priv->base + REG_WDT_MAX_PRD_H);
> +	writew(1, priv->base + REG_WDT_CLR);
> +	return 0;
> +}
> +
> +static int msc313e_wdt_ping(struct watchdog_device *wdev)
> +{
> +	struct msc313e_wdt_priv *priv = watchdog_get_drvdata(wdev);
> +
> +	writew(1, priv->base + REG_WDT_CLR);
> +	return 0;
> +}
> +
> +static int msc313e_wdt_stop(struct watchdog_device *wdev)
> +{
> +	struct msc313e_wdt_priv *priv = watchdog_get_drvdata(wdev);
> +
> +	writew(0, priv->base + REG_WDT_MAX_PRD_L);
> +	writew(0, priv->base + REG_WDT_MAX_PRD_H);
> +	writew(0, priv->base + REG_WDT_CLR);
> +	clk_disable_unprepare(priv->clk);
> +	return 0;
> +}
> +
> +static int msc313e_wdt_settimeout(struct watchdog_device *wdev, unsigned int new_time)
> +{
> +	wdev->timeout = new_time;
> +
> +	return msc313e_wdt_start(wdev);
> +}
> +
> +static const struct watchdog_info msc313e_wdt_ident = {
> +	.identity = "MSC313e watchdog",
> +	.options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT,
> +};
> +
> +static const struct watchdog_ops msc313e_wdt_ops = {
> +	.owner = THIS_MODULE,
> +	.start = msc313e_wdt_start,
> +	.stop = msc313e_wdt_stop,
> +	.ping = msc313e_wdt_ping,
> +	.set_timeout = msc313e_wdt_settimeout,
> +};
> +
> +static const struct of_device_id msc313e_wdt_of_match[] = {
> +	{ .compatible = "mstar,msc313e-wdt", },
> +	{ /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, msc313e_wdt_of_match);
> +
> +static int msc313e_wdt_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct msc313e_wdt_priv *priv;
> +
> +	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	priv->base = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(priv->base))
> +		return PTR_ERR(priv->base);
> +
> +	priv->clk = devm_clk_get(dev, NULL);
> +	if (IS_ERR(priv->clk)) {
> +		dev_err(dev, "No input clock\n");
> +		return PTR_ERR(priv->clk);
> +	}
> +
> +	priv->wdev.info = &msc313e_wdt_ident,
> +	priv->wdev.ops = &msc313e_wdt_ops,
> +	priv->wdev.parent = dev;
> +	priv->wdev.min_timeout = MSC313E_WDT_MIN_TIMEOUT;
> +	priv->wdev.max_timeout = U32_MAX / clk_get_rate(priv->clk);
> +	priv->wdev.timeout = MSC313E_WDT_DEFAULT_TIMEOUT;
> +
> +	watchdog_set_drvdata(&priv->wdev, priv);
> +
> +	watchdog_init_timeout(&priv->wdev, timeout, dev);
> +	watchdog_stop_on_reboot(&priv->wdev);
> +	watchdog_stop_on_unregister(&priv->wdev);
> +
> +	return devm_watchdog_register_device(dev, &priv->wdev);
> +}
> +
> +static int __maybe_unused msc313e_wdt_suspend(struct device *dev)
> +{
> +	struct msc313e_wdt_priv *priv = dev_get_drvdata(dev);
> +
> +	if (watchdog_active(&priv->wdev))
> +		msc313e_wdt_stop(&priv->wdev);
> +
> +	return 0;
> +}
> +
> +static int __maybe_unused msc313e_wdt_resume(struct device *dev)
> +{
> +	struct msc313e_wdt_priv *priv = dev_get_drvdata(dev);
> +
> +	if (watchdog_active(&priv->wdev))
> +		msc313e_wdt_start(&priv->wdev);
> +
> +	return 0;
> +}
> +
> +static SIMPLE_DEV_PM_OPS(msc313e_wdt_pm_ops, msc313e_wdt_suspend, msc313e_wdt_resume);
> +
> +static struct platform_driver msc313e_wdt_driver = {
> +	.driver = {
> +		.name = "msc313e-wdt",
> +		.of_match_table = msc313e_wdt_of_match,
> +		.pm = &msc313e_wdt_pm_ops,
> +	},
> +	.probe = msc313e_wdt_probe,
> +};
> +module_platform_driver(msc313e_wdt_driver);
> +
> +MODULE_AUTHOR("Daniel Palmer <daniel@thingy.jp>");
> +MODULE_DESCRIPTION("Watchdog driver for MStar MSC313e");
> +MODULE_LICENSE("GPL v2");
> -- 
> 2.30.2
> 

  reply	other threads:[~2021-06-05 20:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-05 17:04 [PATCH v3 0/3] Add watchdog for Mstar SoCs Romain Perier
2021-06-05 17:04 ` [PATCH v3 1/3] dt-bindings: watchdog: Add Mstar MSC313e WDT devicetree bindings documentation Romain Perier
2021-06-10 16:57   ` Rob Herring
2021-06-05 17:04 ` [PATCH v3 2/3] watchdog: Add Mstar MSC313e WDT driver Romain Perier
2021-06-05 20:26   ` Guenter Roeck [this message]
2021-06-11 10:34   ` Guenter Roeck
2021-06-11 14:35     ` Romain Perier
2021-06-11 15:13       ` Guenter Roeck
2021-06-05 17:04 ` [PATCH v3 3/3] ARM: dts: mstar: Add watchdog device_node definition Romain Perier

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=20210605202649.GA286016@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=daniel@0x0f.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=mohammed.billoo@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=romain.perier@gmail.com \
    --cc=wim@linux-watchdog.org \
    /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;
as well as URLs for NNTP newsgroup(s).