2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-01-30 21:15:54 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2007-2008
|
2011-10-31 23:00:39 +00:00
|
|
|
* Stelian Pop <stelian@popies.net>
|
2008-01-30 21:15:54 +00:00
|
|
|
* Lead Tech Design <www.leadtechdesign.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2010-11-07 12:26:14 +00:00
|
|
|
#include <asm/io.h>
|
2008-01-30 21:15:54 +00:00
|
|
|
#include <asm/arch/hardware.h>
|
2008-03-26 19:52:32 +00:00
|
|
|
#include <asm/arch/at91_pit.h>
|
2009-04-16 19:30:48 +00:00
|
|
|
#include <asm/arch/clk.h>
|
|
|
|
#include <div64.h>
|
2008-01-30 21:15:54 +00:00
|
|
|
|
2010-10-05 14:54:35 +00:00
|
|
|
#if !defined(CONFIG_AT91FAMILY)
|
|
|
|
# error You need to define CONFIG_AT91FAMILY in your board config!
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2008-01-30 21:15:54 +00:00
|
|
|
/*
|
2008-03-26 19:52:28 +00:00
|
|
|
* We're using the AT91CAP9/SAM9 PITC in 32 bit mode, by
|
2008-01-30 21:15:54 +00:00
|
|
|
* setting the 20 bit counter period to its maximum (0xfffff).
|
2010-10-05 14:54:35 +00:00
|
|
|
* (See the relevant data sheets to understand that this really works)
|
|
|
|
*
|
|
|
|
* We do also mimic the typical powerpc way of incrementing
|
|
|
|
* two 32 bit registers called tbl and tbu.
|
|
|
|
*
|
|
|
|
* Those registers increment at 1/16 the main clock rate.
|
2008-01-30 21:15:54 +00:00
|
|
|
*/
|
|
|
|
|
2010-10-05 14:54:35 +00:00
|
|
|
#define TIMER_LOAD_VAL 0xfffff
|
2009-04-16 19:30:48 +00:00
|
|
|
|
2010-10-05 14:54:35 +00:00
|
|
|
/*
|
|
|
|
* Use the PITC in full 32 bit incrementing mode
|
|
|
|
*/
|
2008-03-26 20:52:27 +00:00
|
|
|
int timer_init(void)
|
2008-01-30 21:15:54 +00:00
|
|
|
{
|
2010-11-03 14:39:55 +00:00
|
|
|
at91_pit_t *pit = (at91_pit_t *) ATMEL_BASE_PIT;
|
2010-10-05 14:54:35 +00:00
|
|
|
|
2016-02-03 02:16:49 +00:00
|
|
|
at91_periph_clk_enable(ATMEL_ID_SYS);
|
2008-01-30 21:15:54 +00:00
|
|
|
|
|
|
|
/* Enable PITC */
|
2010-02-03 21:46:58 +00:00
|
|
|
writel(TIMER_LOAD_VAL | AT91_PIT_MR_EN , &pit->mr);
|
2008-01-30 21:15:54 +00:00
|
|
|
|
2012-12-13 20:48:32 +00:00
|
|
|
gd->arch.timer_rate_hz = gd->arch.mck_rate_hz / 16;
|
2009-04-16 19:30:48 +00:00
|
|
|
|
2008-01-30 21:15:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-10-05 14:54:35 +00:00
|
|
|
* Return the number of timer ticks per second.
|
2008-01-30 21:15:54 +00:00
|
|
|
*/
|
|
|
|
ulong get_tbclk(void)
|
|
|
|
{
|
2012-12-13 20:48:32 +00:00
|
|
|
return gd->arch.timer_rate_hz;
|
2008-01-30 21:15:54 +00:00
|
|
|
}
|