• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Description:
19 */
20 #include <linux/kernel.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/errno.h>
25 #include <linux/platform_device.h>
26 #include <linux/of_device.h>
27 #include <linux/amlogic/cpu_version.h>
28 #include "decoder_cpu_ver_info.h"
29 
30 #define DECODE_CPU_VER_ID_NODE_NAME "cpu_ver_name"
31 #define AM_SUCESS 0
32 #define MAJOR_ID_START AM_MESON_CPU_MAJOR_ID_M6
33 
34 static enum AM_MESON_CPU_MAJOR_ID cpu_ver_id = AM_MESON_CPU_MAJOR_ID_MAX;
35 
36 static enum AM_MESON_CPU_MAJOR_ID cpu_ver_info[AM_MESON_CPU_MAJOR_ID_MAX - MAJOR_ID_START]=
37 {
38 	AM_MESON_CPU_MAJOR_ID_M6,
39 	AM_MESON_CPU_MAJOR_ID_M6TV,
40 	AM_MESON_CPU_MAJOR_ID_M6TVL,
41 	AM_MESON_CPU_MAJOR_ID_M8,
42 	AM_MESON_CPU_MAJOR_ID_MTVD,
43 	AM_MESON_CPU_MAJOR_ID_M8B,
44 	AM_MESON_CPU_MAJOR_ID_MG9TV,
45 	AM_MESON_CPU_MAJOR_ID_M8M2,
46 	AM_MESON_CPU_MAJOR_ID_UNUSE,
47 	AM_MESON_CPU_MAJOR_ID_GXBB,
48 	AM_MESON_CPU_MAJOR_ID_GXTVBB,
49 	AM_MESON_CPU_MAJOR_ID_GXL,
50 	AM_MESON_CPU_MAJOR_ID_GXM,
51 	AM_MESON_CPU_MAJOR_ID_TXL,
52 	AM_MESON_CPU_MAJOR_ID_TXLX,
53 	AM_MESON_CPU_MAJOR_ID_AXG,
54 	AM_MESON_CPU_MAJOR_ID_GXLX,
55 	AM_MESON_CPU_MAJOR_ID_TXHD,
56 	AM_MESON_CPU_MAJOR_ID_G12A,
57 	AM_MESON_CPU_MAJOR_ID_G12B,
58 	AM_MESON_CPU_MAJOR_ID_GXLX2,
59 	AM_MESON_CPU_MAJOR_ID_SM1,
60 	AM_MESON_CPU_MAJOR_ID_RES_0x2c,
61 	AM_MESON_CPU_MAJOR_ID_RES_0x2d,
62 	AM_MESON_CPU_MAJOR_ID_TL1,
63 	AM_MESON_CPU_MAJOR_ID_TM2,
64 };
65 
66 static const struct of_device_id cpu_ver_of_match[] = {
67 	{
68 		.compatible = "amlogic, cpu-major-id-axg",
69 		.data = &cpu_ver_info[AM_MESON_CPU_MAJOR_ID_AXG - MAJOR_ID_START],
70 	},
71 
72 	{
73 		.compatible = "amlogic, cpu-major-id-g12a",
74 		.data = &cpu_ver_info[AM_MESON_CPU_MAJOR_ID_G12A - MAJOR_ID_START],
75 	},
76 
77 	{
78 		.compatible = "amlogic, cpu-major-id-gxl",
79 		.data = &cpu_ver_info[AM_MESON_CPU_MAJOR_ID_GXL - MAJOR_ID_START],
80 	},
81 
82 	{
83 		.compatible = "amlogic, cpu-major-id-gxm",
84 		.data = &cpu_ver_info[AM_MESON_CPU_MAJOR_ID_GXM - MAJOR_ID_START],
85 	},
86 
87 	{
88 		.compatible = "amlogic, cpu-major-id-txl",
89 		.data = &cpu_ver_info[AM_MESON_CPU_MAJOR_ID_TXL - MAJOR_ID_START],
90 	},
91 
92 	{
93 		.compatible = "amlogic, cpu-major-id-txlx",
94 		.data = &cpu_ver_info[AM_MESON_CPU_MAJOR_ID_TXLX - MAJOR_ID_START],
95 	},
96 
97 	{
98 		.compatible = "amlogic, cpu-major-id-sm1",
99 		.data = &cpu_ver_info[AM_MESON_CPU_MAJOR_ID_SM1 - MAJOR_ID_START],
100 	},
101 
102 	{
103 		.compatible = "amlogic, cpu-major-id-tl1",
104 		.data = &cpu_ver_info[AM_MESON_CPU_MAJOR_ID_TL1 - MAJOR_ID_START],
105 	},
106 	{
107 		.compatible = "amlogic, cpu-major-id-tm2",
108 		.data = &cpu_ver_info[AM_MESON_CPU_MAJOR_ID_TM2 - MAJOR_ID_START],
109 	},
110 	{},
111 };
112 
get_cpu_id_from_dtb(enum AM_MESON_CPU_MAJOR_ID * pidType)113 static bool get_cpu_id_from_dtb(enum AM_MESON_CPU_MAJOR_ID *pidType)
114 {
115 	struct device_node *pNode = NULL;
116 	struct platform_device* pDev = NULL;
117 	const struct of_device_id *pMatch = NULL;
118 
119 	pNode = of_find_node_by_name(NULL, DECODE_CPU_VER_ID_NODE_NAME);
120 	if (NULL == pNode) {
121 		pr_err("No find node.\n");
122 		return -EINVAL;
123 	}
124 
125 	pDev =  of_find_device_by_node(pNode);
126 	if (NULL == pDev)
127 		return -EINVAL;
128 
129 	pMatch = of_match_device(cpu_ver_of_match, &pDev->dev);
130 	if (NULL == pMatch) {
131 		pr_err("No find of_match_device\n");
132 		return -EINVAL;
133 	}
134 
135 	*pidType = *(enum AM_MESON_CPU_MAJOR_ID *)pMatch->data;
136 
137 	return AM_SUCESS;
138 }
139 
initial_cpu_id(void)140 static void initial_cpu_id(void)
141 {
142 	enum AM_MESON_CPU_MAJOR_ID id_type = AM_MESON_CPU_MAJOR_ID_MAX;
143 
144 	if (AM_SUCESS == get_cpu_id_from_dtb(&id_type))
145 		cpu_ver_id = id_type;
146 	else
147 		cpu_ver_id = (enum AM_MESON_CPU_MAJOR_ID)get_cpu_type();
148 
149 	if (AM_MESON_CPU_MAJOR_ID_G12B == cpu_ver_id)
150 		if (is_meson_rev_b())
151 			cpu_ver_id = AM_MESON_CPU_MAJOR_ID_TL1;
152 }
153 
get_cpu_major_id(void)154 enum AM_MESON_CPU_MAJOR_ID get_cpu_major_id(void)
155 {
156 	if (AM_MESON_CPU_MAJOR_ID_MAX == cpu_ver_id)
157 		initial_cpu_id();
158 
159 	return cpu_ver_id;
160 }
161 EXPORT_SYMBOL(get_cpu_major_id);
162 
is_cpu_tm2_revb(void)163 bool is_cpu_tm2_revb(void)
164 {
165 	return ((get_cpu_major_id() == AM_MESON_CPU_MAJOR_ID_TM2) &&
166 		(is_meson_rev_b()));
167 }
168 EXPORT_SYMBOL(is_cpu_tm2_revb);
169 
170