From: Weijie Gao <weijie.gao@mediatek.com>
To: u-boot@lists.denx.de
Subject: [PATCH 1/2] timer: mtk_timer: initialize the timer before use
Date: Mon, 18 Jan 2021 08:44:42 +0800 [thread overview]
Message-ID: <1610930682.28105.2.camel@mcddlt001> (raw)
In-Reply-To: <YAHEf/FI9vx9zw0+@ziggy.stardust>
On Fri, 2021-01-15 at 17:36 +0100, Matthias Brugger wrote:
> On Tue, Jan 12, 2021 at 01:44:02PM +0800, Weijie Gao wrote:
> > The timer being used by this driver may have already been used by first
> > stage bootloader (e.g. ATF/preloader), and it's settings may differ from
> > what this driver is going to use.
> >
> > This may cause issues, such as inaccurate timer frequency due to
> > incorrect clock divider.
> >
> > This patch adds the initialization code to avoid them.
> >
> > Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
> > ---
> > drivers/timer/mtk_timer.c | 10 ++++++++++
> > 1 file changed, 10 insertions(+)
> >
> > diff --git a/drivers/timer/mtk_timer.c b/drivers/timer/mtk_timer.c
> > index 448a76a7e1..f6b97f868c 100644
> > --- a/drivers/timer/mtk_timer.c
> > +++ b/drivers/timer/mtk_timer.c
> > @@ -61,6 +61,16 @@ static int mtk_timer_probe(struct udevice *dev)
> > if (!uc_priv->clock_rate)
> > return -EINVAL;
> >
> > + /*
> > + * Initialize the timer:
> > + * 1. set clock source to system clock with clock divider setting to 1
> > + * 2. set timer mode to free running
> > + * 3. reset timer counter to 0 then enable the timer
> > + */
> > + writel(GPT4_CLK_SYS | GPT4_CLK_DIV1, priv->base + MTK_GPT4_CLK);
> > + writel(GPT4_FREERUN | GPT4_CLEAR | GPT4_ENABLE,
>
> GPT4_FREERUN is defined as GENMASK(5,4) while in the Linux kernel it has
> the value of 3. Can you explain where this difference comes from?
GENMASK(5,4) == 3 << 4, which is exactly the same as what's being used
in kernel:
#define GPT_CTRL_OP(val) (((val) & 0x3) << 4)
#define GPT_CTRL_OP_FREERUN (3)
>
> Regards,
> Matthias
>
> > + priv->base + MTK_GPT4_CTRL);
> > +
> > return 0;
> > }
> >
> > --
> > 2.17.1
next prev parent reply other threads:[~2021-01-18 0:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 5:44 [PATCH 1/2] timer: mtk_timer: initialize the timer before use Weijie Gao
2021-01-12 5:44 ` [PATCH 2/2] dts: mt7622: use accurate clock source fot mtk_timer Weijie Gao
2021-01-19 13:06 ` Tom Rini
2021-01-15 16:36 ` [PATCH 1/2] timer: mtk_timer: initialize the timer before use Matthias Brugger
2021-01-18 0:44 ` Weijie Gao [this message]
2021-01-19 10:42 ` Matthias Brugger
2021-01-19 13:06 ` Tom Rini
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=1610930682.28105.2.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