]> git.ipfire.org Git - thirdparty/u-boot.git/blame - arch/arm/mach-at91/armv7/timer.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[thirdparty/u-boot.git] / arch / arm / mach-at91 / armv7 / timer.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
3225f34e
BS
2/*
3 * (C) Copyright 2007-2008
4 * Stelian Pop <stelian@popies.net>
5 * Lead Tech Design <www.leadtechdesign.com>
6 *
7 * (C) Copyright 2013
8 * Bo Shen <voice.shen@atmel.com>
3225f34e
BS
9 */
10
d678a59d 11#include <common.h>
691d719d 12#include <init.h>
049f8d6f 13#include <time.h>
401d1c4f 14#include <asm/global_data.h>
3225f34e
BS
15#include <asm/io.h>
16#include <asm/arch/hardware.h>
17#include <asm/arch/at91_pit.h>
3225f34e
BS
18#include <asm/arch/clk.h>
19#include <div64.h>
20
21#if !defined(CONFIG_AT91FAMILY)
22# error You need to define CONFIG_AT91FAMILY in your board config!
23#endif
24
25DECLARE_GLOBAL_DATA_PTR;
26
27/*
28 * We're using the SAMA5D3x PITC in 32 bit mode, by
29 * setting the 20 bit counter period to its maximum (0xfffff).
30 * (See the relevant data sheets to understand that this really works)
31 *
32 * We do also mimic the typical powerpc way of incrementing
33 * two 32 bit registers called tbl and tbu.
34 *
35 * Those registers increment at 1/16 the main clock rate.
36 */
37
38#define TIMER_LOAD_VAL 0xfffff
39
3225f34e
BS
40/*
41 * Use the PITC in full 32 bit incrementing mode
42 */
43int timer_init(void)
44{
45 at91_pit_t *pit = (at91_pit_t *)ATMEL_BASE_PIT;
46
47 /* Enable PITC Clock */
184c551b 48 at91_periph_clk_enable(ATMEL_ID_PIT);
3225f34e
BS
49
50 /* Enable PITC */
51 writel(TIMER_LOAD_VAL | AT91_PIT_MR_EN , &pit->mr);
52
927b901b
BS
53 gd->arch.timer_rate_hz = get_pit_clk_rate() / 16;
54
3225f34e
BS
55 return 0;
56}
57
3225f34e
BS
58/*
59 * Return the number of timer ticks per second.
60 */
61ulong get_tbclk(void)
62{
63 return gd->arch.timer_rate_hz;
64}