2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-09-13 20:23:35 +00:00
|
|
|
/*
|
2017-01-17 15:27:26 +00:00
|
|
|
* Copyright (C) 2017 Weidmüller Interface GmbH & Co. KG
|
|
|
|
* Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
|
|
|
|
*
|
2012-09-13 20:23:35 +00:00
|
|
|
* Copyright (C) 2012 Michal Simek <monstr@monstr.eu>
|
2018-01-17 06:37:47 +00:00
|
|
|
* Copyright (C) 2011-2017 Xilinx, Inc. All rights reserved.
|
2012-09-13 20:23:35 +00:00
|
|
|
*
|
|
|
|
* (C) Copyright 2008
|
|
|
|
* Guennadi Liakhovetki, DENX Software Engineering, <lg@denx.de>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2004
|
|
|
|
* Philippe Robin, ARM Ltd. <philippe.robin@arm.com>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002-2004
|
|
|
|
* Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2003
|
|
|
|
* Texas Instruments <www.ti.com>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Marius Groeger <mgroeger@sysgo.de>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Alex Zuepke <azu@sysgo.de>
|
|
|
|
*/
|
|
|
|
|
2017-01-17 15:27:26 +00:00
|
|
|
#include <clk.h>
|
2012-09-13 20:23:35 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <div64.h>
|
2017-01-17 15:27:26 +00:00
|
|
|
#include <dm.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2019-12-28 17:44:59 +00:00
|
|
|
#include <time.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2012-09-13 20:23:35 +00:00
|
|
|
#include <asm/io.h>
|
2013-04-12 14:21:26 +00:00
|
|
|
#include <asm/arch/hardware.h>
|
2013-11-21 21:38:57 +00:00
|
|
|
#include <asm/arch/clk.h>
|
2012-09-13 20:23:35 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
struct scu_timer {
|
|
|
|
u32 load; /* Timer Load Register */
|
|
|
|
u32 counter; /* Timer Counter Register */
|
|
|
|
u32 control; /* Timer Control Register */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct scu_timer *timer_base =
|
2013-04-12 14:21:26 +00:00
|
|
|
(struct scu_timer *)ZYNQ_SCUTIMER_BASEADDR;
|
2012-09-13 20:23:35 +00:00
|
|
|
|
|
|
|
#define SCUTIMER_CONTROL_PRESCALER_MASK 0x0000FF00 /* Prescaler */
|
|
|
|
#define SCUTIMER_CONTROL_PRESCALER_SHIFT 8
|
|
|
|
#define SCUTIMER_CONTROL_AUTO_RELOAD_MASK 0x00000002 /* Auto-reload */
|
|
|
|
#define SCUTIMER_CONTROL_ENABLE_MASK 0x00000001 /* Timer enable */
|
|
|
|
|
|
|
|
#define TIMER_LOAD_VAL 0xFFFFFFFF
|
|
|
|
#define TIMER_PRESCALE 255
|
|
|
|
|
|
|
|
int timer_init(void)
|
|
|
|
{
|
|
|
|
const u32 emask = SCUTIMER_CONTROL_AUTO_RELOAD_MASK |
|
|
|
|
(TIMER_PRESCALE << SCUTIMER_CONTROL_PRESCALER_SHIFT) |
|
|
|
|
SCUTIMER_CONTROL_ENABLE_MASK;
|
|
|
|
|
2017-01-17 15:27:26 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
struct clk clk;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_CLK,
|
2020-12-29 03:34:56 +00:00
|
|
|
DM_DRIVER_GET(zynq_clk), &dev);
|
2017-01-17 15:27:26 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
clk.id = cpu_6or4x_clk;
|
|
|
|
ret = clk_request(dev, &clk);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
gd->cpu_clk = clk_get_rate(&clk);
|
|
|
|
|
|
|
|
clk_free(&clk);
|
|
|
|
|
2013-11-22 14:29:38 +00:00
|
|
|
gd->arch.timer_rate_hz = (gd->cpu_clk / 2) / (TIMER_PRESCALE + 1);
|
2013-11-21 21:38:57 +00:00
|
|
|
|
2012-09-13 20:23:35 +00:00
|
|
|
/* Load the timer counter register */
|
2013-08-28 05:36:31 +00:00
|
|
|
writel(0xFFFFFFFF, &timer_base->load);
|
2012-09-13 20:23:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the A9Timer device
|
|
|
|
* Enable Auto reload mode, Clear prescaler control bits
|
|
|
|
* Set prescaler value, Enable the decrementer
|
|
|
|
*/
|
|
|
|
clrsetbits_le32(&timer_base->control, SCUTIMER_CONTROL_PRESCALER_MASK,
|
|
|
|
emask);
|
|
|
|
|
|
|
|
/* Reset time */
|
2012-12-13 20:48:35 +00:00
|
|
|
gd->arch.lastinc = readl(&timer_base->counter) /
|
2013-11-21 21:38:57 +00:00
|
|
|
(gd->arch.timer_rate_hz / CONFIG_SYS_HZ);
|
2012-12-13 20:48:34 +00:00
|
|
|
gd->arch.tbl = 0;
|
2012-09-13 20:23:35 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is derived from PowerPC code (timebase clock frequency).
|
|
|
|
* On ARM it returns the number of timer ticks per second.
|
|
|
|
*/
|
|
|
|
ulong get_tbclk(void)
|
|
|
|
{
|
2015-04-20 10:56:24 +00:00
|
|
|
return gd->arch.timer_rate_hz;
|
2012-09-13 20:23:35 +00:00
|
|
|
}
|