Merge tag 'u-boot-rockchip-20200531' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / drivers / timer / dw-apb-timer.c
index 031f429acb884f3fbcc17bb4ba1d3e514ce3ff51..35271b20c891e9585cf95bb16ca5e42177a0435b 100644 (file)
@@ -8,7 +8,10 @@
 #include <common.h>
 #include <dm.h>
 #include <clk.h>
+#include <malloc.h>
+#include <reset.h>
 #include <timer.h>
+#include <dm/device_compat.h>
 
 #include <asm/io.h>
 #include <asm/arch/timer.h>
 #define DW_APB_CURR_VAL                0x4
 #define DW_APB_CTRL            0x8
 
-DECLARE_GLOBAL_DATA_PTR;
-
 struct dw_apb_timer_priv {
-       fdt_addr_t      regs;
+       fdt_addr_t regs;
+       struct reset_ctl_bulk resets;
 };
 
 static int dw_apb_timer_get_count(struct udevice *dev, u64 *count)
@@ -32,7 +34,7 @@ static int dw_apb_timer_get_count(struct udevice *dev, u64 *count)
         * requires the count to be incrementing. Invert the
         * result.
         */
-       *count = ~readl(priv->regs + DW_APB_CURR_VAL);
+       *count = timer_conv_64(~readl(priv->regs + DW_APB_CURR_VAL));
 
        return 0;
 }
@@ -44,6 +46,12 @@ static int dw_apb_timer_probe(struct udevice *dev)
        struct clk clk;
        int ret;
 
+       ret = reset_get_bulk(dev, &priv->resets);
+       if (ret)
+               dev_warn(dev, "Can't get reset: %d\n", ret);
+       else
+               reset_deassert_bulk(&priv->resets);
+
        ret = clk_get_by_index(dev, 0, &clk);
        if (ret)
                return ret;
@@ -69,6 +77,13 @@ static int dw_apb_timer_ofdata_to_platdata(struct udevice *dev)
        return 0;
 }
 
+static int dw_apb_timer_remove(struct udevice *dev)
+{
+       struct dw_apb_timer_priv *priv = dev_get_priv(dev);
+
+       return reset_release_bulk(&priv->resets);
+}
+
 static const struct timer_ops dw_apb_timer_ops = {
        .get_count      = dw_apb_timer_get_count,
 };
@@ -83,8 +98,8 @@ U_BOOT_DRIVER(dw_apb_timer) = {
        .id             = UCLASS_TIMER,
        .ops            = &dw_apb_timer_ops,
        .probe          = dw_apb_timer_probe,
-       .flags          = DM_FLAG_PRE_RELOC,
        .of_match       = dw_apb_timer_ids,
        .ofdata_to_platdata = dw_apb_timer_ofdata_to_platdata,
+       .remove         = dw_apb_timer_remove,
        .priv_auto_alloc_size = sizeof(struct dw_apb_timer_priv),
 };