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
|
#include "ccu.h"
#include <stdlib.h>
#include <hal_clk.h>
extern int sunxi_fixed_clk_init(void);
extern int sunxi_ccu_init(void);
extern int sunxi_r_ccu_init(void);
extern int sunxi_rtc_ccu_init(void);
hal_clk_status_t clk_init(void)
{
sunxi_fixed_clk_init();
sunxi_rtc_ccu_init();
sunxi_r_ccu_init();
sunxi_ccu_init();
return 0;
}
struct clk *clk_get(hal_clk_type_t type, hal_clk_id_t id)
{
struct clk_core *core = NULL;
struct clk *clk = NULL;
core = clk_core_get(type, id);
if (!core)
{
return NULL;
}
clk = core->clk;
clk->count++;
return clk;
}
hal_clk_status_t clk_put(struct clk *clk)
{
if (!clk)
{
return 0;
}
if (clk->count)
clk->count--;
return 0;
}
hal_clk_status_t clk_is_enabled(struct clk *clk)
{
int ret = 0;
if (clk)
{
ret = clk_core_is_enabled(clk->core);
}
return ret ? 0 : -1;
}
hal_clk_status_t clk_prepare_enable(struct clk *clk)
{
if (!clk)
{
return 0;
}
return clk_core_enable(clk->core);
}
hal_clk_status_t clk_disable_unprepare(struct clk *clk)
{
if (clk)
{
return clk_core_disable(clk->core);
}
return 0;
}
struct clk *clk_get_parent(struct clk *clk)
{
struct clk_core *parent;
struct clk *p_clk;
if (!clk)
{
return NULL;
}
parent = clk_core_get_parent(clk->core);
if (!parent)
return NULL;
if (parent->clk)
{
p_clk = parent->clk;
p_clk->count++;
}
else
{
p_clk = (struct clk *)malloc(sizeof(*clk));
p_clk->core = parent;
p_clk->name = parent->name;
p_clk->count = 1;
parent->clk = p_clk;
}
return p_clk;
}
hal_clk_status_t clk_set_parent(struct clk *clk, struct clk *p_clk)
{
int ret;
if (!clk || !p_clk)
{
return -1;
}
ret = clk_core_set_parent(clk->core, p_clk->core);
if (ret)
{
return ret;
}
return ret;
}
hal_clk_status_t clk_get_rate(struct clk *clk, u32 *rate)
{
if (!clk)
{
*rate = 0;
}
else
{
*rate = clk_core_get_rate(clk->core);
}
return 0;
}
hal_clk_status_t clk_set_rate(struct clk *clk, u32 rate)
{
struct clk *p_clk;
if (!clk)
{
return 0;
}
p_clk = clk_get_parent(clk);
return clk_core_set_rate(clk->core, p_clk->core, rate);
}
hal_clk_status_t clk_recalc_rate(struct clk *clk, u32 *rate)
{
struct clk *p_clk;
if (!clk)
{
return 0;
}
p_clk = clk_get_parent(clk);
*rate = clk_core_recalc_rate(clk->core, p_clk->core);
return 0;
}
hal_clk_status_t clk_round_rate(struct clk *clk, u32 rate, u32 *round_rate)
{
if (!clk)
{
round_rate = 0;
return 0;
}
*round_rate = clk_core_round_rate(clk->core, rate);
return 0;
}
|