1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2007-2008
5 * Lead Tech Design <www.leadtechdesign.com>
15 #include <asm/arch/hardware.h>
16 #include <asm/arch/at91_pit.h>
17 #include <asm/arch/clk.h>
20 #if !defined(CONFIG_AT91FAMILY)
21 # error You need to define CONFIG_AT91FAMILY in your board config!
24 DECLARE_GLOBAL_DATA_PTR;
27 * We're using the SAMA5D3x PITC in 32 bit mode, by
28 * setting the 20 bit counter period to its maximum (0xfffff).
29 * (See the relevant data sheets to understand that this really works)
31 * We do also mimic the typical powerpc way of incrementing
32 * two 32 bit registers called tbl and tbu.
34 * Those registers increment at 1/16 the main clock rate.
37 #define TIMER_LOAD_VAL 0xfffff
40 * Use the PITC in full 32 bit incrementing mode
44 at91_pit_t *pit = (at91_pit_t *)ATMEL_BASE_PIT;
46 /* Enable PITC Clock */
47 at91_periph_clk_enable(ATMEL_ID_PIT);
50 writel(TIMER_LOAD_VAL | AT91_PIT_MR_EN , &pit->mr);
52 gd->arch.timer_rate_hz = get_pit_clk_rate() / 16;
58 * Return the number of timer ticks per second.
62 return gd->arch.timer_rate_hz;