1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Weidmüller Interface GmbH & Co. KG
4 * Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
6 * Copyright (C) 2012 Michal Simek <monstr@monstr.eu>
7 * Copyright (C) 2011-2017 Xilinx, Inc. All rights reserved.
10 * Guennadi Liakhovetki, DENX Software Engineering, <lg@denx.de>
13 * Philippe Robin, ARM Ltd. <philippe.robin@arm.com>
15 * (C) Copyright 2002-2004
16 * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
19 * Texas Instruments <www.ti.com>
22 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
23 * Marius Groeger <mgroeger@sysgo.de>
26 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
27 * Alex Zuepke <azu@sysgo.de>
35 #include <asm/arch/hardware.h>
36 #include <asm/arch/clk.h>
38 DECLARE_GLOBAL_DATA_PTR;
41 u32 load; /* Timer Load Register */
42 u32 counter; /* Timer Counter Register */
43 u32 control; /* Timer Control Register */
46 static struct scu_timer *timer_base =
47 (struct scu_timer *)ZYNQ_SCUTIMER_BASEADDR;
49 #define SCUTIMER_CONTROL_PRESCALER_MASK 0x0000FF00 /* Prescaler */
50 #define SCUTIMER_CONTROL_PRESCALER_SHIFT 8
51 #define SCUTIMER_CONTROL_AUTO_RELOAD_MASK 0x00000002 /* Auto-reload */
52 #define SCUTIMER_CONTROL_ENABLE_MASK 0x00000001 /* Timer enable */
54 #define TIMER_LOAD_VAL 0xFFFFFFFF
55 #define TIMER_PRESCALE 255
59 const u32 emask = SCUTIMER_CONTROL_AUTO_RELOAD_MASK |
60 (TIMER_PRESCALE << SCUTIMER_CONTROL_PRESCALER_SHIFT) |
61 SCUTIMER_CONTROL_ENABLE_MASK;
67 ret = uclass_get_device_by_driver(UCLASS_CLK,
68 DM_GET_DRIVER(zynq_clk), &dev);
72 clk.id = cpu_6or4x_clk;
73 ret = clk_request(dev, &clk);
77 gd->cpu_clk = clk_get_rate(&clk);
81 gd->arch.timer_rate_hz = (gd->cpu_clk / 2) / (TIMER_PRESCALE + 1);
83 /* Load the timer counter register */
84 writel(0xFFFFFFFF, &timer_base->load);
87 * Start the A9Timer device
88 * Enable Auto reload mode, Clear prescaler control bits
89 * Set prescaler value, Enable the decrementer
91 clrsetbits_le32(&timer_base->control, SCUTIMER_CONTROL_PRESCALER_MASK,
95 gd->arch.lastinc = readl(&timer_base->counter) /
96 (gd->arch.timer_rate_hz / CONFIG_SYS_HZ);
103 * This function is derived from PowerPC code (timebase clock frequency).
104 * On ARM it returns the number of timer ticks per second.
106 ulong get_tbclk(void)
108 return gd->arch.timer_rate_hz;