From: Patrice CHOTARD Date: Thu, 12 Mar 2020 12:37:52 +0000 Subject: [PATCH 2/2] timer: sti: use clk API to get timer clock rate In-Reply-To: <20200308132057.256-3-nicolas.heemeryck@gmail.com> References: <20200308132057.256-1-nicolas.heemeryck@gmail.com> <20200308132057.256-3-nicolas.heemeryck@gmail.com> Message-ID: <6f1bcf09-4a30-99a5-bade-400d222502fd@st.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Nicolas On 3/8/20 2:20 PM, Nicolas Heemeryck wrote: > Retrieve clock rate through device tree. This mimics the behavior of > arm_global_timer in Linux. > > Signed-off-by: Nicolas Heemeryck > --- > drivers/timer/sti-timer.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/drivers/timer/sti-timer.c b/drivers/timer/sti-timer.c > index eac22ae39b..123fac04a9 100644 > --- a/drivers/timer/sti-timer.c > +++ b/drivers/timer/sti-timer.c > @@ -6,6 +6,7 @@ > > #include > #include > +#include > #include > > #include > @@ -41,14 +42,22 @@ static int sti_timer_probe(struct udevice *dev) > { > struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); > struct sti_timer_priv *priv = dev_get_priv(dev); > - > - uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK; > + struct clk clk; > + int ret; > > /* get arm global timer base address */ > priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev); > if (!priv->global_timer) > return -ENOENT; > > + ret = clk_get_by_index(dev, 0, &clk); > + if (ret) > + return ret; > + > + uc_priv->clock_rate = clk_get_rate(&clk); > + if (!uc_priv->clock_rate) > + return -EINVAL; > + > /* init timer */ > writel(0x01, &priv->global_timer->ctl); > Nack, for STi board, there is no clock driver (all clock are enabled by default). So clk_get_by_index() will return an error and will avoid timer driver to probe properly. Thanks Patrice