From patchwork Fri Mar 13 22:42:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Heemeryck X-Patchwork-Id: 243689 List-Id: U-Boot discussion From: nicolas.heemeryck at gmail.com (Nicolas Heemeryck) Date: Fri, 13 Mar 2020 23:42:43 +0100 Subject: [PATCH v2 1/2] timer: sti: convert to livetree In-Reply-To: <20200313224244.4502-1-nicolas.heemeryck@gmail.com> References: <6f1bcf09-4a30-99a5-bade-400d222502fd@st.com> <20200313224244.4502-1-nicolas.heemeryck@gmail.com> Message-ID: <20200313224244.4502-2-nicolas.heemeryck@gmail.com> Update STI timer to support a live tree Signed-off-by: Nicolas Heemeryck Cc: Patrice Chotard Acked-by: Patrice Chotard --- Changes for v2: None --- drivers/timer/sti-timer.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/timer/sti-timer.c b/drivers/timer/sti-timer.c index 9def7e02f4..eac22ae39b 100644 --- a/drivers/timer/sti-timer.c +++ b/drivers/timer/sti-timer.c @@ -6,14 +6,11 @@ #include #include -#include #include #include #include -DECLARE_GLOBAL_DATA_PTR; - struct sti_timer_priv { struct globaltimer *global_timer; }; @@ -44,13 +41,13 @@ 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); - fdt_addr_t addr; uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK; /* get arm global timer base address */ - addr = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev), "reg"); - priv->global_timer = (struct globaltimer *)addr; + priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev); + if (!priv->global_timer) + return -ENOENT; /* init timer */ writel(0x01, &priv->global_timer->ctl); From patchwork Fri Mar 13 22:42:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Heemeryck X-Patchwork-Id: 243690 List-Id: U-Boot discussion From: nicolas.heemeryck at gmail.com (Nicolas Heemeryck) Date: Fri, 13 Mar 2020 23:42:44 +0100 Subject: [PATCH v2 2/2] timer: sti: use clk API to get timer clock rate In-Reply-To: <20200313224244.4502-1-nicolas.heemeryck@gmail.com> References: <6f1bcf09-4a30-99a5-bade-400d222502fd@st.com> <20200313224244.4502-1-nicolas.heemeryck@gmail.com> Message-ID: <20200313224244.4502-3-nicolas.heemeryck@gmail.com> Retrieve clock rate through device tree. This mimics the behavior of arm_global_timer in Linux. Signed-off-by: Nicolas Heemeryck Cc: Patrice Chotard Acked-by: Patrice Chotard --- Changes for v2: - Fall back on CONFIG_SYS_HZ_CLOCK if clk_get_by_index returns an error or no clock driver is provided. --- drivers/timer/sti-timer.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/timer/sti-timer.c b/drivers/timer/sti-timer.c index eac22ae39b..ff42056abd 100644 --- a/drivers/timer/sti-timer.c +++ b/drivers/timer/sti-timer.c @@ -6,7 +6,9 @@ #include #include +#include #include +#include #include #include @@ -41,14 +43,25 @@ 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 err; + ulong ret; /* get arm global timer base address */ priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev); if (!priv->global_timer) return -ENOENT; + err = clk_get_by_index(dev, 0, &clk); + if (!err) { + ret = clk_get_rate(&clk); + if (IS_ERR_VALUE(ret)) + return ret; + uc_priv->clock_rate = ret; + } else { + uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK; + } + /* init timer */ writel(0x01, &priv->global_timer->ctl);