1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2010-2015, Intel Corporation.
5  */
6 
7 #include <type_support.h> /*uint32_t */
8 #include "gp_timer.h"   /*system_local.h,
9 			  gp_timer_public.h*/
10 
11 #ifndef __INLINE_GP_TIMER__
12 #include "gp_timer_private.h"  /*device_access.h*/
13 #endif /* __INLINE_GP_TIMER__ */
14 #include "system_local.h"
15 
16 /* FIXME: not sure if reg_load(), reg_store() should be API.
17  */
18 static uint32_t
19 gp_timer_reg_load(uint32_t reg);
20 
21 static void
22 gp_timer_reg_store(u32 reg, uint32_t value);
23 
24 static uint32_t
gp_timer_reg_load(uint32_t reg)25 gp_timer_reg_load(uint32_t reg)
26 {
27 	return ia_css_device_load_uint32(
28 		   GP_TIMER_BASE +
29 		   (reg * sizeof(uint32_t)));
30 }
31 
32 static void
gp_timer_reg_store(u32 reg,uint32_t value)33 gp_timer_reg_store(u32 reg, uint32_t value)
34 {
35 	ia_css_device_store_uint32((GP_TIMER_BASE +
36 				    (reg * sizeof(uint32_t))),
37 				   value);
38 }
39 
gp_timer_init(gp_timer_ID_t ID)40 void gp_timer_init(gp_timer_ID_t ID)
41 {
42 	/* set_overall_enable*/
43 	gp_timer_reg_store(_REG_GP_TIMER_OVERALL_ENABLE, 1);
44 
45 	/*set enable*/
46 	gp_timer_reg_store(_REG_GP_TIMER_ENABLE_ID(ID), 1);
47 
48 	/* set signal select */
49 	gp_timer_reg_store(_REG_GP_TIMER_SIGNAL_SELECT_ID(ID), GP_TIMER_SIGNAL_SELECT);
50 
51 	/*set count type */
52 	gp_timer_reg_store(_REG_GP_TIMER_COUNT_TYPE_ID(ID), GP_TIMER_COUNT_TYPE_LOW);
53 
54 	/*reset gp timer */
55 	gp_timer_reg_store(_REG_GP_TIMER_RESET_REG, 0xFF);
56 }
57 
58 uint32_t
gp_timer_read(gp_timer_ID_t ID)59 gp_timer_read(gp_timer_ID_t ID)
60 {
61 	return	gp_timer_reg_load(_REG_GP_TIMER_VALUE_ID(ID));
62 }
63