All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] timer: Support clocks via phandle
@ 2016-11-17 17:08 Vlad Zakharov
  2016-11-19 13:47 ` Simon Glass
  0 siblings, 1 reply; 2+ messages in thread
From: Vlad Zakharov @ 2016-11-17 17:08 UTC (permalink / raw)
  To: u-boot

Earlier timer driver needed a clock-frequency property in compatible
device-tree nodes. Another way is to reference a clock via a phandle.

So now timer_pre_probe tries to get clock by reference through device
tree. In case it is impossible to get clock device through the
reference, clock-frequency property of the timer node is read to provide
backward compatibility.

Signed-off-by: Vlad Zakharov <vzakhar@synopsys.com>
---
 drivers/timer/timer-uclass.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
index f8ddf93..cca41f1 100644
--- a/drivers/timer/timer-uclass.c
+++ b/drivers/timer/timer-uclass.c
@@ -8,6 +8,7 @@
 #include <dm.h>
 #include <dm/lists.h>
 #include <dm/device-internal.h>
+#include <clk.h>
 #include <errno.h>
 #include <timer.h>
 
@@ -42,9 +43,17 @@ unsigned long notrace timer_get_rate(struct udevice *dev)
 static int timer_pre_probe(struct udevice *dev)
 {
 	struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-
-	uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
-					     "clock-frequency", 0);
+	struct clk *timer_clk;
+	int err;
+
+	err = clk_get_by_index(dev, 0, timer_clk);
+	if (!err) {
+		uc_priv->clock_rate = clk_get_rate(timer_clk);
+		if (uc_priv->clock_rate < 0)
+			return uc_priv->clock_rate;
+	} else
+		uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob,
+				dev->of_offset,	"clock-frequency", 0);
 
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] timer: Support clocks via phandle
  2016-11-17 17:08 [U-Boot] [PATCH] timer: Support clocks via phandle Vlad Zakharov
@ 2016-11-19 13:47 ` Simon Glass
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Glass @ 2016-11-19 13:47 UTC (permalink / raw)
  To: u-boot

Hi Vlad,

On 17 November 2016 at 10:08, Vlad Zakharov
<Vladislav.Zakharov@synopsys.com> wrote:
> Earlier timer driver needed a clock-frequency property in compatible
> device-tree nodes. Another way is to reference a clock via a phandle.
>
> So now timer_pre_probe tries to get clock by reference through device
> tree. In case it is impossible to get clock device through the
> reference, clock-frequency property of the timer node is read to provide
> backward compatibility.
>
> Signed-off-by: Vlad Zakharov <vzakhar@synopsys.com>
> ---
>  drivers/timer/timer-uclass.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
> index f8ddf93..cca41f1 100644
> --- a/drivers/timer/timer-uclass.c
> +++ b/drivers/timer/timer-uclass.c
> @@ -8,6 +8,7 @@
>  #include <dm.h>
>  #include <dm/lists.h>
>  #include <dm/device-internal.h>
> +#include <clk.h>
>  #include <errno.h>
>  #include <timer.h>
>
> @@ -42,9 +43,17 @@ unsigned long notrace timer_get_rate(struct udevice *dev)
>  static int timer_pre_probe(struct udevice *dev)
>  {
>         struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
> -
> -       uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
> -                                            "clock-frequency", 0);
> +       struct clk *timer_clk;
> +       int err;
> +
> +       err = clk_get_by_index(dev, 0, timer_clk);
> +       if (!err) {
> +               uc_priv->clock_rate = clk_get_rate(timer_clk);

Please use a temporary variable here, like:

   ret = clk_get_rate(timer_clk);
   if (IS_ERR_VALUE(ret))
      return ret;
   uc_priv->clock_rate = ret;

> +               if (uc_priv->clock_rate < 0)
> +                       return uc_priv->clock_rate;
> +       } else
> +               uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob,
> +                               dev->of_offset, "clock-frequency", 0);
>
>         return 0;
>  }
> --
> 2.7.4
>

Regards,
SImon

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-19 13:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-17 17:08 [U-Boot] [PATCH] timer: Support clocks via phandle Vlad Zakharov
2016-11-19 13:47 ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.