1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Weidmüller Interface GmbH & Co. KG
7 * Copyright (C) 2011-2017 Xilinx, Inc. All rights reserved.
15 * (C) Copyright 2002-2004
19 * Texas Instruments <www.ti.com>
22 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
26 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
37 #include <asm/global_data.h>
39 #include <asm/arch/hardware.h>
40 #include <asm/arch/clk.h>
42 DECLARE_GLOBAL_DATA_PTR;
45 u32 load; /* Timer Load Register */
46 u32 counter; /* Timer Counter Register */
47 u32 control; /* Timer Control Register */
50 static struct scu_timer *timer_base =
51 (struct scu_timer *)ZYNQ_SCUTIMER_BASEADDR;
53 #define SCUTIMER_CONTROL_PRESCALER_MASK 0x0000FF00 /* Prescaler */
54 #define SCUTIMER_CONTROL_PRESCALER_SHIFT 8
55 #define SCUTIMER_CONTROL_AUTO_RELOAD_MASK 0x00000002 /* Auto-reload */
56 #define SCUTIMER_CONTROL_ENABLE_MASK 0x00000001 /* Timer enable */
58 #define TIMER_LOAD_VAL 0xFFFFFFFF
59 #define TIMER_PRESCALE 255
63 const u32 emask = SCUTIMER_CONTROL_AUTO_RELOAD_MASK |
64 (TIMER_PRESCALE << SCUTIMER_CONTROL_PRESCALER_SHIFT) |
65 SCUTIMER_CONTROL_ENABLE_MASK;
71 ret = uclass_get_device_by_driver(UCLASS_CLK,
72 DM_DRIVER_GET(zynq_clk), &dev);
76 clk.id = cpu_6or4x_clk;
77 ret = clk_request(dev, &clk);
81 gd->cpu_clk = clk_get_rate(&clk);
85 gd->arch.timer_rate_hz = (gd->cpu_clk / 2) / (TIMER_PRESCALE + 1);
87 /* Load the timer counter register */
88 writel(0xFFFFFFFF, &timer_base->load);
91 * Start the A9Timer device
92 * Enable Auto reload mode, Clear prescaler control bits
93 * Set prescaler value, Enable the decrementer
95 clrsetbits_le32(&timer_base->control, SCUTIMER_CONTROL_PRESCALER_MASK,
99 gd->arch.lastinc = readl(&timer_base->counter) /
100 (gd->arch.timer_rate_hz / CONFIG_SYS_HZ);
107 * This function is derived from PowerPC code (timebase clock frequency).
108 * On ARM it returns the number of timer ticks per second.
110 ulong get_tbclk(void)
112 return gd->arch.timer_rate_hz;