hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2022 Rockchip Electronics Co. Ltd.
 *
 * Author: Joseph Chen <chenjh@rock-chips.com>
 */
 
#ifndef _CRU_API_H_
#define _CRU_API_H_
 
#include "hal_def.h"
#include "hal_os_def.h"
#include "cru_core.h"
#include "cru_rkx110.h"
#include "cru_rkx120.h"
#include "cru_rkx111.h"
#include "cru_rkx121.h"
 
static HAL_DEFINE_MUTEX(top_lock);
 
static inline bool hwclk_is_enabled(struct hwclk *hw, uint32_t clk)
{
    bool ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkIsEnabled(hw, clk);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline int hwclk_enable(struct hwclk *hw, uint32_t clk)
{
    int ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkEnable(hw, clk);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline int hwclk_disable(struct hwclk *hw, uint32_t clk)
{
    int ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkDisable(hw, clk);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline bool hwclk_is_reset(struct hwclk *hw, uint32_t clk)
{
    bool ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkIsReset(hw, clk);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline int hwclk_reset(struct hwclk *hw, uint32_t clk)
{
    int ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkResetAssert(hw, clk);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline int hwclk_reset_deassert(struct hwclk *hw, uint32_t clk)
{
    int ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkResetDeassert(hw, clk);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline int hwclk_set_div(struct hwclk *hw, uint32_t clk, uint32_t div)
{
    int ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkSetDiv(hw, clk, div);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline uint32_t hwclk_get_div(struct hwclk *hw, uint32_t clk)
{
    uint32_t ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkGetDiv(hw, clk);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline int hwclk_set_mux(struct hwclk *hw, uint32_t clk, uint32_t mux)
{
    int ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkSetMux(hw, clk, mux);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline uint32_t hwclk_get_mux(struct hwclk *hw, uint32_t clk)
{
    uint32_t ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkGetMux(hw, clk);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline uint32_t hwclk_get_rate(struct hwclk *hw, uint32_t composite_clk)
{
    uint32_t ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkGetFreq(hw, composite_clk);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline int hwclk_set_rate(struct hwclk *hw, uint32_t composite_clk, uint32_t rate)
{
    int ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkSetFreq(hw, composite_clk, rate);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline int hwclk_set_testout(struct hwclk *hw, uint32_t composite_clk,
                                    uint32_t mux, uint32_t div)
{
    int ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_ClkSetTestout(hw, composite_clk, mux, div);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline void hwclk_dump_tree(HAL_ClockType type)
{
    HAL_MutexLock(&top_lock);
    HAL_CRU_ClkDumpTree(type);
    HAL_MutexUnlock(&top_lock);
}
 
static inline int hwclk_set_glbsrst(struct hwclk *hw, uint32_t type)
{
    int ret;
 
    HAL_MutexLock(&hw->lock);
    ret = HAL_CRU_SetGlbSrst(hw, type);
    HAL_MutexUnlock(&hw->lock);
 
    return ret;
}
 
static inline struct hwclk *hwclk_register(struct xferclk xfer)
{
    struct hwclk *ret;
 
    HAL_MutexLock(&top_lock);
    ret = HAL_CRU_Register(xfer);
    HAL_MutexUnlock(&top_lock);
 
    return ret;
}
 
static inline struct hwclk *hwclk_get(void *client)
{
    struct hwclk *ret;
 
    HAL_MutexLock(&top_lock);
    ret = HAL_CRU_ClkGet(client);
    HAL_MutexUnlock(&top_lock);
 
    return ret;
}
 
static inline int hwclk_init(void)
{
    return HAL_CRU_Init();
}
 
#endif