Home | History | Annotate | Download | only in sp804
      1 /*
      2  * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
      3  *
      4  * SPDX-License-Identifier: BSD-3-Clause
      5  */
      6 
      7 #include <assert.h>
      8 #include <delay_timer.h>
      9 #include <mmio.h>
     10 
     11 uintptr_t sp804_base_addr;
     12 
     13 #define SP804_TIMER1_LOAD	(sp804_base_addr + 0x000)
     14 #define SP804_TIMER1_VALUE	(sp804_base_addr + 0x004)
     15 #define SP804_TIMER1_CONTROL	(sp804_base_addr + 0x008)
     16 #define SP804_TIMER1_BGLOAD	(sp804_base_addr + 0x018)
     17 
     18 #define TIMER_CTRL_ONESHOT	(1 << 0)
     19 #define TIMER_CTRL_32BIT	(1 << 1)
     20 #define TIMER_CTRL_DIV1		(0 << 2)
     21 #define TIMER_CTRL_DIV16	(1 << 2)
     22 #define TIMER_CTRL_DIV256	(2 << 2)
     23 #define TIMER_CTRL_IE		(1 << 5)
     24 #define TIMER_CTRL_PERIODIC	(1 << 6)
     25 #define TIMER_CTRL_ENABLE	(1 << 7)
     26 
     27 /********************************************************************
     28  * The SP804 timer delay function
     29  ********************************************************************/
     30 uint32_t sp804_get_timer_value(void)
     31 {
     32 	return mmio_read_32(SP804_TIMER1_VALUE);
     33 }
     34 
     35 /********************************************************************
     36  * Initialize the 1st timer in the SP804 dual timer with a base
     37  * address and a timer ops
     38  ********************************************************************/
     39 void sp804_timer_ops_init(uintptr_t base_addr, const timer_ops_t *ops)
     40 {
     41 	assert(base_addr != 0);
     42 	assert(ops != 0 && ops->get_timer_value == sp804_get_timer_value);
     43 
     44 	sp804_base_addr = base_addr;
     45 	timer_init(ops);
     46 
     47 	/* disable timer1 */
     48 	mmio_write_32(SP804_TIMER1_CONTROL, 0);
     49 	mmio_write_32(SP804_TIMER1_LOAD, UINT32_MAX);
     50 	mmio_write_32(SP804_TIMER1_VALUE, UINT32_MAX);
     51 
     52 	/* enable as a free running 32-bit counter */
     53 	mmio_write_32(SP804_TIMER1_CONTROL,
     54 			TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE);
     55 }
     56