From: Weijie Gao <weijie.gao@mediatek.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 14/21] watchdog: add watchdog driver for MediaTek MT7620 SoC
Date: Mon, 9 Nov 2020 10:13:14 +0800 [thread overview]
Message-ID: <1604887994.18736.41.camel@mcddlt001> (raw)
In-Reply-To: <CAMty3ZDi2aUnTuM5RGgvVK46wHXRhpSmsgA7tA+iU5VYs+050A@mail.gmail.com>
On Mon, 2020-11-02 at 11:32 +0530, Jagan Teki wrote:
> On Fri, Oct 30, 2020 at 3:04 PM Weijie Gao <weijie.gao@mediatek.com> wrote:
> >
> > This patch adds watchdog support for the Mediatek MT7620 SoC
> >
> > Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
> > ---
> > v2 changes: add expire_now
> > ---
> > drivers/watchdog/Kconfig | 7 ++
> > drivers/watchdog/Makefile | 1 +
> > drivers/watchdog/mt7620_wdt.c | 132 ++++++++++++++++++++++++++++++++++
> > 3 files changed, 140 insertions(+)
> > create mode 100644 drivers/watchdog/mt7620_wdt.c
> >
> > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> > index 210d9f8093..35d078caa0 100644
> > --- a/drivers/watchdog/Kconfig
> > +++ b/drivers/watchdog/Kconfig
> > @@ -124,6 +124,13 @@ config WDT_MPC8xx
> > help
> > Select this to enable mpc8xx watchdog timer
> >
> > +config WDT_MT7620
> > + bool "MediaTek MT7620 watchdog timer support"
> > + depends on WDT && SOC_MT7620
> > + help
> > + Select this to enable watchdog timer on MediaTek MT7620 and earlier
> > + SoC chips.
> > +
> > config WDT_MT7621
> > bool "MediaTek MT7621 watchdog timer support"
> > depends on WDT && SOC_MT7628
> > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> > index 01b8231f2b..825b50e626 100644
> > --- a/drivers/watchdog/Makefile
> > +++ b/drivers/watchdog/Makefile
> > @@ -24,6 +24,7 @@ obj-$(CONFIG_WDT_CORTINA) += cortina_wdt.o
> > obj-$(CONFIG_WDT_ORION) += orion_wdt.o
> > obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o
> > obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o
> > +obj-$(CONFIG_WDT_MT7620) += mt7620_wdt.o
> > obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.o
> > obj-$(CONFIG_WDT_MTK) += mtk_wdt.o
> > obj-$(CONFIG_WDT_OCTEONTX) += octeontx_wdt.o
> > diff --git a/drivers/watchdog/mt7620_wdt.c b/drivers/watchdog/mt7620_wdt.c
> > new file mode 100644
> > index 0000000000..2643167f8f
> > --- /dev/null
> > +++ b/drivers/watchdog/mt7620_wdt.c
> > @@ -0,0 +1,132 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright (C) 2020 MediaTek Inc.
> > + *
> > + * Author: Weijie Gao <weijie.gao@mediatek.com>
> > + *
> > + * Watchdog timer for MT7620 and earlier SoCs
> > + */
> > +
> > +#include <div64.h>
> > +#include <dm.h>
> > +#include <reset.h>
> > +#include <wdt.h>
> > +#include <linux/bitops.h>
> > +#include <linux/io.h>
> > +
> > +struct mt7620_wdt {
> > + void __iomem *regs;
> > + u64 timeout;
> > +};
> > +
> > +#define TIMER_FREQ 40000000
> > +#define TIMER_MASK 0xffff
> > +#define TIMER_PRESCALE 65536
> > +
> > +#define TIMER_LOAD 0x00
> > +#define TIMER_CTL 0x08
> > +
> > +#define TIMER_ENABLE BIT(7)
> > +#define TIMER_MODE_SHIFT 4
> > +#define TIMER_MODE_WDT 3
> > +#define TIMER_PRESCALE_SHIFT 0
> > +#define TIMER_PRESCALE_65536 15
> > +
> > +static void mt7620_wdt_ping(struct mt7620_wdt *priv)
> > +{
> > + u64 val;
> > +
> > + val = (TIMER_FREQ / TIMER_PRESCALE) * priv->timeout;
> > + do_div(val, 1000);
> > +
> > + if (val > TIMER_MASK)
> > + val = TIMER_MASK;
> > +
> > + writel(val, priv->regs + TIMER_LOAD);
> > +}
> > +
> > +static int mt7620_wdt_start(struct udevice *dev, u64 ms, ulong flags)
> > +{
> > + struct mt7620_wdt *priv = dev_get_priv(dev);
> > +
> > + priv->timeout = ms;
> > + mt7620_wdt_ping(priv);
> > +
> > + writel(TIMER_ENABLE | (TIMER_MODE_WDT << TIMER_MODE_SHIFT) |
> > + (TIMER_PRESCALE_65536 << TIMER_PRESCALE_SHIFT),
> > + priv->regs + TIMER_CTL);
> > +
> > + return 0;
> > +}
> > +
> > +static int mt7620_wdt_stop(struct udevice *dev)
> > +{
> > + struct mt7620_wdt *priv = dev_get_priv(dev);
> > +
> > + mt7620_wdt_ping(priv);
> > +
> > + clrbits_32(priv->regs + TIMER_CTL, TIMER_ENABLE);
> > +
> > + return 0;
> > +}
> > +
> > +static int mt7620_wdt_reset(struct udevice *dev)
> > +{
> > + struct mt7620_wdt *priv = dev_get_priv(dev);
> > +
> > + mt7620_wdt_ping(priv);
> > +
> > + return 0;
> > +}
> > +
> > +static int mt7620_wdt_expire_now(struct udevice *dev, ulong flags)
> > +{
> > + struct mt7620_wdt *priv = dev_get_priv(dev);
> > +
> > + mt7620_wdt_start(dev, 1, flags);
> > +
> > + /* 0 will disable the timer, so use 1 instead */
> > + writel(1, priv->regs + TIMER_LOAD);
>
> Better replace the magic number with macro.
> Otherwise,
this line means load timer with value 1. Since the timer is a countdown,
1 is the smallest value to cause a wdt timeout.
>
> Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
next prev parent reply other threads:[~2020-11-09 2:13 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-30 9:33 [PATCH v2 00/21] Add support for MediaTek MT7620 SoC Weijie Gao
2020-10-30 9:33 ` [PATCH v2 01/21] mips: dts: switch to board defines for dtb for mtmips Weijie Gao
2020-10-30 9:33 ` [PATCH v2 02/21] mips: mtmips: move mt7628 related Kconfig into mt7628 subdirectory Weijie Gao
2020-10-30 9:33 ` [PATCH v2 03/21] mips: mtmips: select SYSRESET for mt7628 only Weijie Gao
2020-10-30 9:33 ` [PATCH v2 04/21] mips: mtmips: fix dram size detection in dram_init Weijie Gao
2020-10-30 9:33 ` [PATCH v2 05/21] mips: enable _machine_restart for spl Weijie Gao
2020-11-03 15:12 ` Simon Glass
2020-10-30 9:34 ` [PATCH v2 06/21] mips: mtmips: add support to initialize SDRAM Weijie Gao
2020-10-30 9:34 ` [PATCH v2 07/21] mips: mtmips: add support for MediaTek MT7620 SoC Weijie Gao
2020-10-30 9:34 ` [PATCH v2 08/21] mips: mtmips: add two reference boards for mt7620 Weijie Gao
2020-10-30 9:34 ` [PATCH v2 09/21] configs: mtmips: refresh for mt7628 based boards Weijie Gao
2020-10-30 9:34 ` [PATCH v2 10/21] serial: add uart driver for MediaTek MT7620 SoC Weijie Gao
2020-11-03 15:12 ` Simon Glass
2020-10-30 9:34 ` [PATCH v2 11/21] clk: add clock " Weijie Gao
2020-10-30 9:34 ` [PATCH v2 12/21] reset: mtmips: add reset controller support " Weijie Gao
2020-10-30 9:34 ` [PATCH v2 13/21] pinctrl: mtmips: add " Weijie Gao
2020-10-30 9:34 ` [PATCH v2 14/21] watchdog: add watchdog driver " Weijie Gao
2020-11-02 6:02 ` Jagan Teki
2020-11-09 2:13 ` Weijie Gao [this message]
2020-10-30 9:34 ` [PATCH v2 15/21] gpio: add GPIO controller " Weijie Gao
2020-10-30 9:35 ` [PATCH v2 16/21] spi: add spi controller support " Weijie Gao
2020-11-02 6:00 ` Jagan Teki
2020-11-09 2:10 ` Weijie Gao
2020-10-30 9:35 ` [PATCH v2 17/21] phy: add USB PHY driver " Weijie Gao
2020-11-02 6:11 ` Jagan Teki
2020-11-09 2:14 ` Weijie Gao
2020-10-30 9:35 ` [PATCH v2 18/21] net: add ethernet " Weijie Gao
2020-10-30 9:35 ` [PATCH v2 19/21] mmc: mtk-sd: add pad control settings for MediaTek MT7620/MT76x8 SoCs Weijie Gao
2020-10-30 9:35 ` [PATCH v2 20/21] reset: reset-mtmips: add DM_FLAG_PRE_RELOC flag Weijie Gao
2020-10-30 9:35 ` [PATCH v2 21/21] MAINTAINERS: add maintainer for MediaTek MIPS platform Weijie Gao
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=1604887994.18736.41.camel@mcddlt001 \
--to=weijie.gao@mediatek.com \
--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