1/* 2 * Copyright 2019, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12#pragma once 13 14#include <platsupport/fdt.h> 15#include <platsupport/ltimer.h> 16#include <platsupport/timer.h> 17 18#define RK_TIMER_PATH "/rktimer@ff850000" 19 20#define RK_REG_CHOICE 0 21#define RK_IRQ_CHOICE 0 22 23static UNUSED timer_properties_t rk_properties = { 24 .upcounter = true, 25 .timeouts = true, 26 .relative_timeouts = true, 27 .periodic_timeouts = true, 28 .bit_width = 32, 29 .irqs = 1 30}; 31 32struct rk_map { 33 uint32_t load_count0; 34 uint32_t load_count1; 35 uint32_t current_value0; 36 uint32_t current_value1; 37 uint32_t load_count2; 38 uint32_t load_count3; 39 uint32_t interrupt_status; 40 uint32_t control_register; 41}; 42 43typedef struct { 44 /* set in init */ 45 ps_io_ops_t ops; 46 ltimer_callback_fn_t user_cb_fn; 47 void *user_cb_token; 48 ltimer_event_t user_cb_event; /* what are we being used for? */ 49 50 /* set in fdt helper */ 51 volatile struct rk_map *hw; 52 void *rk_map_base; 53 pmem_region_t pmem; 54 ps_irq_t irq; 55 irq_id_t irq_id; 56} rk_t; 57 58typedef struct { 59 char *fdt_path; 60 ltimer_callback_fn_t user_cb_fn; 61 void *user_cb_token; 62 ltimer_event_t user_cb_event; 63} rk_config_t; 64 65int rk_init(rk_t *rk, ps_io_ops_t ops, rk_config_t config); 66int rk_init_secondary(rk_t *rk, rk_t *rkp, ps_io_ops_t ops, rk_config_t config); 67int rk_start_timestamp_timer(rk_t *rk); 68int rk_stop(rk_t *rk); 69uint64_t rk_get_time(rk_t *rk); 70int rk_set_timeout(rk_t *rk, uint64_t ns, bool periodic); 71/* return true if a match is pending */ 72bool rk_pending_match(rk_t *rk); 73void rk_destroy(rk_t *rk); 74