hc
2024-03-26 e9199a72d842cbda78ac614eee5db7cdaa6f2530
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
 * Copyright (C) 2017 Rockchip Electronics Co. Ltd.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 */
 
#ifndef __LINUX_ROCKCHIP_CPU_H
#define __LINUX_ROCKCHIP_CPU_H
 
#include <linux/of.h>
 
#define ROCKCHIP_CPU_MASK        0xffff0000
#define ROCKCHIP_CPU_SHIFT        16
#define ROCKCHIP_CPU_PX30        0x33260000
#define ROCKCHIP_CPU_RV1103        0x11030000
#define ROCKCHIP_CPU_RV1106        0x11060000
#define ROCKCHIP_CPU_RV1109        0x11090000
#define ROCKCHIP_CPU_RV1126        0x11260000
#define ROCKCHIP_CPU_RK312X        0x31260000
#define ROCKCHIP_CPU_RK3288        0x32880000
#define ROCKCHIP_CPU_RK3308        0x33080000
#define ROCKCHIP_CPU_RK3528        0x35280000
#define ROCKCHIP_CPU_RK3566        0x35660000
#define ROCKCHIP_CPU_RK3567        0x35670000
#define ROCKCHIP_CPU_RK3568        0x35680000
 
#if IS_REACHABLE(CONFIG_ROCKCHIP_CPUINFO)
 
extern unsigned long rockchip_soc_id;
 
#define ROCKCHIP_CPU_VERION_MASK    0x0000f000
#define ROCKCHIP_CPU_VERION_SHIFT    12
 
static inline unsigned long rockchip_get_cpu_version(void)
{
   return (rockchip_soc_id & ROCKCHIP_CPU_VERION_MASK)
       >> ROCKCHIP_CPU_VERION_SHIFT;
}
 
static inline void rockchip_set_cpu_version(unsigned long ver)
{
   rockchip_soc_id &= ~ROCKCHIP_CPU_VERION_MASK;
   rockchip_soc_id |=
       (ver << ROCKCHIP_CPU_VERION_SHIFT) & ROCKCHIP_CPU_VERION_MASK;
}
 
static inline void rockchip_set_cpu(unsigned long code)
{
   if (!code)
       return;
 
   rockchip_soc_id &= ~ROCKCHIP_CPU_MASK;
   rockchip_soc_id |= (code << ROCKCHIP_CPU_SHIFT) & ROCKCHIP_CPU_MASK;
}
 
int rockchip_soc_id_init(void);
 
#else
 
#define rockchip_soc_id 0
 
static inline unsigned long rockchip_get_cpu_version(void)
{
   return 0;
}
 
static inline void rockchip_set_cpu_version(unsigned long ver)
{
}
 
static inline void rockchip_set_cpu(unsigned long code)
{
}
 
static inline int rockchip_soc_id_init(void)
{
   return 0;
}
 
#endif
 
#ifdef CONFIG_CPU_PX30
static inline bool cpu_is_px30(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_PX30;
   return of_machine_is_compatible("rockchip,px30") ||
          of_machine_is_compatible("rockchip,px30s") ||
          of_machine_is_compatible("rockchip,rk3326") ||
          of_machine_is_compatible("rockchip,rk3326s");
}
#else
static inline bool cpu_is_px30(void) { return false; }
#endif
 
#if defined(CONFIG_CPU_RV1106)
static inline bool cpu_is_rv1103(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_RV1103;
   return of_machine_is_compatible("rockchip,rv1103");
}
 
static inline bool cpu_is_rv1106(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_RV1106;
   return of_machine_is_compatible("rockchip,rv1106");
}
#else
static inline bool cpu_is_rv1103(void) { return false; }
static inline bool cpu_is_rv1106(void) { return false; }
#endif
 
#if defined(CONFIG_CPU_RV1126) || defined(CONFIG_CPU_RV1109)
static inline bool cpu_is_rv1109(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_RV1109;
   return of_machine_is_compatible("rockchip,rv1109");
}
 
static inline bool cpu_is_rv1126(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_RV1126;
   return of_machine_is_compatible("rockchip,rv1126");
}
#else
static inline bool cpu_is_rv1109(void) { return false; }
static inline bool cpu_is_rv1126(void) { return false; }
#endif
 
#ifdef CONFIG_CPU_RK312X
static inline bool cpu_is_rk312x(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_RK312X;
   return of_machine_is_compatible("rockchip,rk3126") ||
          of_machine_is_compatible("rockchip,rk3126b") ||
          of_machine_is_compatible("rockchip,rk3126c") ||
          of_machine_is_compatible("rockchip,rk3128");
}
#else
static inline bool cpu_is_rk312x(void) { return false; }
#endif
 
#ifdef CONFIG_CPU_RK3288
static inline bool cpu_is_rk3288(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_RK3288;
   return of_machine_is_compatible("rockchip,rk3288") ||
          of_machine_is_compatible("rockchip,rk3288w");
}
#else
static inline bool cpu_is_rk3288(void) { return false; }
#endif
 
#ifdef CONFIG_CPU_RK3308
static inline bool cpu_is_rk3308(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_RK3308;
 
   return of_machine_is_compatible("rockchip,rk3308") ||
          of_machine_is_compatible("rockchip,rk3308bs");
}
#else
static inline bool cpu_is_rk3308(void) { return false; }
#endif
 
#if defined(CONFIG_CPU_RK3528)
static inline bool cpu_is_rk3528(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_RK3528;
   return of_machine_is_compatible("rockchip,rk3528") ||
          of_machine_is_compatible("rockchip,rk3528a");
}
#else
static inline bool cpu_is_rk3528(void) { return false; }
#endif
 
#if defined(CONFIG_CPU_RK3568)
static inline bool cpu_is_rk3566(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_RK3566;
   return of_machine_is_compatible("rockchip,rk3566");
}
 
static inline bool cpu_is_rk3567(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_RK3567;
   return of_machine_is_compatible("rockchip,rk3567");
}
 
static inline bool cpu_is_rk3568(void)
{
   if (rockchip_soc_id)
       return (rockchip_soc_id & ROCKCHIP_CPU_MASK) == ROCKCHIP_CPU_RK3568;
   return of_machine_is_compatible("rockchip,rk3568");
}
#else
static inline bool cpu_is_rk3566(void) { return false; }
static inline bool cpu_is_rk3567(void) { return false; }
static inline bool cpu_is_rk3568(void) { return false; }
#endif
 
#define ROCKCHIP_SOC_MASK    (ROCKCHIP_CPU_MASK | 0xff)
#define ROCKCHIP_SOC_PX30    (ROCKCHIP_CPU_PX30 | 0x00)
#define ROCKCHIP_SOC_PX30S    (ROCKCHIP_CPU_PX30 | 0x01)
#define ROCKCHIP_SOC_RV1103     (ROCKCHIP_CPU_RV1103 | 0x00)
#define ROCKCHIP_SOC_RV1106     (ROCKCHIP_CPU_RV1106 | 0x00)
#define ROCKCHIP_SOC_RV1109     (ROCKCHIP_CPU_RV1109 | 0x00)
#define ROCKCHIP_SOC_RV1126     (ROCKCHIP_CPU_RV1126 | 0x00)
#define ROCKCHIP_SOC_RK3126     (ROCKCHIP_CPU_RK312X | 0x00)
#define ROCKCHIP_SOC_RK3126B    (ROCKCHIP_CPU_RK312X | 0x10)
#define ROCKCHIP_SOC_RK3126C    (ROCKCHIP_CPU_RK312X | 0x20)
#define ROCKCHIP_SOC_RK3128     (ROCKCHIP_CPU_RK312X | 0x01)
#define ROCKCHIP_SOC_RK3288     (ROCKCHIP_CPU_RK3288 | 0x00)
#define ROCKCHIP_SOC_RK3288W    (ROCKCHIP_CPU_RK3288 | 0x01)
#define ROCKCHIP_SOC_RK3308    (ROCKCHIP_CPU_RK3308 | 0x00)
#define ROCKCHIP_SOC_RK3308B    (ROCKCHIP_CPU_RK3308 | 0x01)
#define ROCKCHIP_SOC_RK3308BS    (ROCKCHIP_CPU_RK3308 | 0x02)
#define ROCKCHIP_SOC_RK3528    (ROCKCHIP_CPU_RK3528 | 0x00)
#define ROCKCHIP_SOC_RK3528A    (ROCKCHIP_CPU_RK3528 | 0x01)
#define ROCKCHIP_SOC_RK3566    (ROCKCHIP_CPU_RK3566 | 0x00)
#define ROCKCHIP_SOC_RK3567    (ROCKCHIP_CPU_RK3567 | 0x00)
#define ROCKCHIP_SOC_RK3568    (ROCKCHIP_CPU_RK3568 | 0x00)
 
#define ROCKCHIP_SOC(CPU, id, ID) \
static inline bool soc_is_##id(void) \
{ \
   if (!IS_ENABLED(CONFIG_CPU_##CPU)) \
       return false; \
   if (rockchip_soc_id) \
       return ((rockchip_soc_id & ROCKCHIP_SOC_MASK) == ROCKCHIP_SOC_ ##ID); \
   return of_machine_is_compatible("rockchip,"#id); \
}
 
ROCKCHIP_SOC(PX30, px30, PX30)
ROCKCHIP_SOC(PX30, px30s, PX30S)
ROCKCHIP_SOC(RV1106, rv1103, RV1103)
ROCKCHIP_SOC(RV1106, rv1106, RV1106)
ROCKCHIP_SOC(RV1126, rv1109, RV1109)
ROCKCHIP_SOC(RV1126, rv1126, RV1126)
ROCKCHIP_SOC(RK312X, rk3126, RK3126)
ROCKCHIP_SOC(RK312X, rk3126b, RK3126B)
ROCKCHIP_SOC(RK312X, rk3126c, RK3126C)
ROCKCHIP_SOC(RK312X, rk3128, RK3128)
ROCKCHIP_SOC(RK3288, rk3288, RK3288)
ROCKCHIP_SOC(RK3288, rk3288w, RK3288W)
ROCKCHIP_SOC(RK3308, rk3308, RK3308)
ROCKCHIP_SOC(RK3308, rk3308b, RK3308B)
ROCKCHIP_SOC(RK3308, rk3308bs, RK3308BS)
ROCKCHIP_SOC(RK3528, rk3528, RK3528)
ROCKCHIP_SOC(RK3528, rk3528a, RK3528A)
ROCKCHIP_SOC(RK3568, rk3566, RK3566)
ROCKCHIP_SOC(RK3567, rk3567, RK3567)
ROCKCHIP_SOC(RK3568, rk3568, RK3568)
 
#endif