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 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 */
15
16 #include <type_support.h> /*uint32_t */
17 #include "gp_timer.h" /*system_local.h,
18 gp_timer_public.h*/
19
20 #ifndef __INLINE_GP_TIMER__
21 #include "gp_timer_private.h" /*device_access.h*/
22 #endif /* __INLINE_GP_TIMER__ */
23 #include "system_local.h"
24
25 /* FIXME: not sure if reg_load(), reg_store() should be API.
26 */
27 static uint32_t
28 gp_timer_reg_load(uint32_t reg);
29
30 static void
31 gp_timer_reg_store(u32 reg, uint32_t value);
32
33 static uint32_t
gp_timer_reg_load(uint32_t reg)34 gp_timer_reg_load(uint32_t reg)
35 {
36 return ia_css_device_load_uint32(
37 GP_TIMER_BASE +
38 (reg * sizeof(uint32_t)));
39 }
40
41 static void
gp_timer_reg_store(u32 reg,uint32_t value)42 gp_timer_reg_store(u32 reg, uint32_t value)
43 {
44 ia_css_device_store_uint32((GP_TIMER_BASE +
45 (reg * sizeof(uint32_t))),
46 value);
47 }
48
gp_timer_init(gp_timer_ID_t ID)49 void gp_timer_init(gp_timer_ID_t ID)
50 {
51 /* set_overall_enable*/
52 gp_timer_reg_store(_REG_GP_TIMER_OVERALL_ENABLE, 1);
53
54 /*set enable*/
55 gp_timer_reg_store(_REG_GP_TIMER_ENABLE_ID(ID), 1);
56
57 /* set signal select */
58 gp_timer_reg_store(_REG_GP_TIMER_SIGNAL_SELECT_ID(ID), GP_TIMER_SIGNAL_SELECT);
59
60 /*set count type */
61 gp_timer_reg_store(_REG_GP_TIMER_COUNT_TYPE_ID(ID), GP_TIMER_COUNT_TYPE_LOW);
62
63 /*reset gp timer */
64 gp_timer_reg_store(_REG_GP_TIMER_RESET_REG, 0xFF);
65 }
66
67 uint32_t
gp_timer_read(gp_timer_ID_t ID)68 gp_timer_read(gp_timer_ID_t ID)
69 {
70 return gp_timer_reg_load(_REG_GP_TIMER_VALUE_ID(ID));
71 }
72