]> Git Repo - J-u-boot.git/blobdiff - drivers/timer/cadence-ttc.c
Merge branch 'next-clk-sync' of https://source.denx.de/u-boot/custodians/u-boot-sh
[J-u-boot.git] / drivers / timer / cadence-ttc.c
index 3541e5c841278fa308697ef94876406ebd7f9634..3cffb1bb88db59b7cc84821b73d73c06131e9fc7 100644 (file)
@@ -3,11 +3,15 @@
  * Copyright (C) 2018 Xilinx, Inc. (Michal Simek)
  */
 
-#include <common.h>
+#include <bootstage.h>
 #include <dm.h>
 #include <errno.h>
+#include <init.h>
 #include <timer.h>
+#include <asm/global_data.h>
 #include <asm/io.h>
+#include <linux/bitops.h>
+#include <linux/err.h>
 
 #define CNT_CNTRL_RESET                BIT(4)
 
@@ -31,13 +35,33 @@ struct cadence_ttc_priv {
        struct cadence_ttc_regs *regs;
 };
 
-static int cadence_ttc_get_count(struct udevice *dev, u64 *count)
+#if CONFIG_IS_ENABLED(BOOTSTAGE)
+ulong timer_get_boot_us(void)
 {
-       struct cadence_ttc_priv *priv = dev_get_priv(dev);
+       u64 ticks = 0;
+       u32 rate = 1;
+       u64 us;
+       int ret;
+
+       ret = dm_timer_init();
+       if (!ret) {
+               /* The timer is available */
+               rate = timer_get_rate(gd->timer);
+               timer_get_count(gd->timer, &ticks);
+       } else {
+               return 0;
+       }
+
+       us = (ticks * 1000) / rate;
+       return us;
+}
+#endif
 
-       *count = readl(&priv->regs->counter_val1);
+static u64 cadence_ttc_get_count(struct udevice *dev)
+{
+       struct cadence_ttc_priv *priv = dev_get_priv(dev);
 
-       return 0;
+       return readl(&priv->regs->counter_val1);
 }
 
 static int cadence_ttc_probe(struct udevice *dev)
@@ -60,7 +84,7 @@ static int cadence_ttc_probe(struct udevice *dev)
        return 0;
 }
 
-static int cadence_ttc_ofdata_to_platdata(struct udevice *dev)
+static int cadence_ttc_of_to_plat(struct udevice *dev)
 {
        struct cadence_ttc_priv *priv = dev_get_priv(dev);
 
@@ -72,6 +96,17 @@ static int cadence_ttc_ofdata_to_platdata(struct udevice *dev)
        return 0;
 }
 
+static int cadence_ttc_bind(struct udevice *dev)
+{
+       const char *cells;
+
+       cells = dev_read_prop(dev, "#pwm-cells", NULL);
+       if (cells)
+               return -ENODEV;
+
+       return 0;
+}
+
 static const struct timer_ops cadence_ttc_ops = {
        .get_count = cadence_ttc_get_count,
 };
@@ -85,9 +120,9 @@ U_BOOT_DRIVER(cadence_ttc) = {
        .name = "cadence_ttc",
        .id = UCLASS_TIMER,
        .of_match = cadence_ttc_ids,
-       .ofdata_to_platdata = cadence_ttc_ofdata_to_platdata,
-       .priv_auto_alloc_size = sizeof(struct cadence_ttc_priv),
+       .of_to_plat = cadence_ttc_of_to_plat,
+       .priv_auto      = sizeof(struct cadence_ttc_priv),
        .probe = cadence_ttc_probe,
        .ops = &cadence_ttc_ops,
-       .flags = DM_FLAG_PRE_RELOC,
+       .bind = cadence_ttc_bind,
 };
This page took 0.024667 seconds and 4 git commands to generate.