• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 Rockchip Electronics Co. Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details.
12  */
13 
14 #ifndef __LINUX_ROCKCHIP_CPU_H
15 #define __LINUX_ROCKCHIP_CPU_H
16 
17 #include <linux/of.h>
18 #define ROCKCHIP_CPU_MASK		0xffff0000
19 #define ROCKCHIP_CPU_SHIFT		16
20 
21 #if IS_ENABLED(CONFIG_ROCKCHIP_CPUINFO)
22 
23 extern unsigned long rockchip_soc_id;
24 
25 #define ROCKCHIP_CPU_VERION_MASK	0x0000f000
26 #define ROCKCHIP_CPU_VERION_SHIFT	12
27 
rockchip_get_cpu_version(void)28 static inline unsigned long rockchip_get_cpu_version(void)
29 {
30 	return (rockchip_soc_id & ROCKCHIP_CPU_VERION_MASK)
31 		>> ROCKCHIP_CPU_VERION_SHIFT;
32 }
33 
rockchip_set_cpu_version(unsigned long ver)34 static inline void rockchip_set_cpu_version(unsigned long ver)
35 {
36 	rockchip_soc_id &= ~ROCKCHIP_CPU_VERION_MASK;
37 	rockchip_soc_id |=
38 		(ver << ROCKCHIP_CPU_VERION_SHIFT) & ROCKCHIP_CPU_VERION_MASK;
39 }
40 
rockchip_set_cpu(unsigned long code)41 static inline void rockchip_set_cpu(unsigned long code)
42 {
43 	if (!code)
44 		return;
45 
46 	rockchip_soc_id &= ~ROCKCHIP_CPU_MASK;
47 	rockchip_soc_id |= (code << ROCKCHIP_CPU_SHIFT) & ROCKCHIP_CPU_MASK;
48 }
49 #else
50 
51 #define rockchip_soc_id 0
52 
rockchip_get_cpu_version(void)53 static inline unsigned long rockchip_get_cpu_version(void)
54 {
55 	return 0;
56 }
57 
rockchip_set_cpu_version(unsigned long ver)58 static inline void rockchip_set_cpu_version(unsigned long ver)
59 {
60 }
61 
rockchip_set_cpu(unsigned long code)62 static inline void rockchip_set_cpu(unsigned long code)
63 {
64 }
65 #endif
66 
67 #define ROCKCHIP_SOC(id, ID) \
68 static inline bool soc_is_##id(void) \
69 { \
70 	if (rockchip_soc_id) \
71 		return ((rockchip_soc_id & ROCKCHIP_SOC_MASK) == ROCKCHIP_SOC_ ##ID); \
72 	return of_machine_is_compatible("rockchip,"#id); \
73 }
74 
75 #endif
76