blob: a0bcf38f29f304a3a437c2280397fe9aafd366ba [file] [log] [blame]
Julien Massonf41d7232019-03-25 11:55:29 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2019 Julien Masson <jmasson@baylibre.com>
4 * (C) Copyright 2019 Neil Armstrong <narmstrong@baylibre.com>
5 */
6
7#include <common.h>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Julien Massonf41d7232019-03-25 11:55:29 +01009#include <asm/io.h>
10#include <dm.h>
11#include <linux/bitfield.h>
12#include <regmap.h>
13#include <syscon.h>
Simon Glasscd93d622020-05-10 11:40:13 -060014#include <linux/bitops.h>
Simon Glass61b29b82020-02-03 07:36:15 -070015#include <linux/err.h>
Julien Massonf41d7232019-03-25 11:55:29 +010016
17#define AO_SEC_SD_CFG8 0xe0
18#define AO_SEC_SOCINFO_OFFSET AO_SEC_SD_CFG8
19
20#define SOCINFO_MAJOR GENMASK(31, 24)
21#define SOCINFO_PACK GENMASK(23, 16)
22#define SOCINFO_MINOR GENMASK(15, 8)
23#define SOCINFO_MISC GENMASK(7, 0)
24
25static const struct meson_gx_soc_id {
26 const char *name;
27 unsigned int id;
28} soc_ids[] = {
29 { "GXBB", 0x1f },
30 { "GXTVBB", 0x20 },
31 { "GXL", 0x21 },
32 { "GXM", 0x22 },
33 { "TXL", 0x23 },
34 { "TXLX", 0x24 },
35 { "AXG", 0x25 },
36 { "GXLX", 0x26 },
37 { "TXHD", 0x27 },
38 { "G12A", 0x28 },
39 { "G12B", 0x29 },
Neil Armstrongdabd6a92019-10-11 17:33:51 +020040 { "SM1", 0x2b },
Neil Armstrongb6a71e22020-11-09 14:30:01 +010041 { "A1", 0x2c },
Julien Massonf41d7232019-03-25 11:55:29 +010042};
43
44static const struct meson_gx_package_id {
45 const char *name;
46 unsigned int major_id;
47 unsigned int pack_id;
48 unsigned int pack_mask;
49} soc_packages[] = {
50 { "S905", 0x1f, 0, 0x20 }, /* pack_id != 0x20 */
51 { "S905H", 0x1f, 0x3, 0xf }, /* pack_id & 0xf == 0x3 */
52 { "S905M", 0x1f, 0x20, 0xf0 }, /* pack_id == 0x20 */
53 { "S905D", 0x21, 0, 0xf0 },
54 { "S905X", 0x21, 0x80, 0xf0 },
55 { "S905W", 0x21, 0xa0, 0xf0 },
56 { "S905L", 0x21, 0xc0, 0xf0 },
57 { "S905M2", 0x21, 0xe0, 0xf0 },
58 { "S805X", 0x21, 0x30, 0xf0 },
59 { "S805Y", 0x21, 0xb0, 0xf0 },
60 { "S912", 0x22, 0, 0x0 }, /* Only S912 is known for GXM */
61 { "962X", 0x24, 0x10, 0xf0 },
62 { "962E", 0x24, 0x20, 0xf0 },
63 { "A113X", 0x25, 0x37, 0xff },
64 { "A113D", 0x25, 0x22, 0xff },
65 { "S905D2", 0x28, 0x10, 0xf0 },
66 { "S905X2", 0x28, 0x40, 0xf0 },
Andreas Färber57212ff2019-10-09 16:03:57 +020067 { "A311D", 0x29, 0x10, 0xf0 },
Julien Massonf41d7232019-03-25 11:55:29 +010068 { "S922X", 0x29, 0x40, 0xf0 },
Neil Armstrongb6a71e22020-11-09 14:30:01 +010069 { "S905D3", 0x2b, 0x4, 0xf5 },
70 { "S905X3", 0x2b, 0x5, 0xf5 },
71 { "S905X3", 0x2b, 0x10, 0x3f },
72 { "S905D3", 0x2b, 0x30, 0x3f },
73 { "A113L", 0x2c, 0x0, 0xf8 },
Julien Massonf41d7232019-03-25 11:55:29 +010074};
75
76DECLARE_GLOBAL_DATA_PTR;
77
78static inline unsigned int socinfo_to_major(u32 socinfo)
79{
80 return FIELD_GET(SOCINFO_MAJOR, socinfo);
81}
82
83static inline unsigned int socinfo_to_minor(u32 socinfo)
84{
85 return FIELD_GET(SOCINFO_MINOR, socinfo);
86}
87
88static inline unsigned int socinfo_to_pack(u32 socinfo)
89{
90 return FIELD_GET(SOCINFO_PACK, socinfo);
91}
92
93static inline unsigned int socinfo_to_misc(u32 socinfo)
94{
95 return FIELD_GET(SOCINFO_MISC, socinfo);
96}
97
98static const char *socinfo_to_package_id(u32 socinfo)
99{
100 unsigned int pack = socinfo_to_pack(socinfo);
101 unsigned int major = socinfo_to_major(socinfo);
102 int i;
103
104 for (i = 0 ; i < ARRAY_SIZE(soc_packages) ; ++i) {
105 if (soc_packages[i].major_id == major &&
106 soc_packages[i].pack_id ==
107 (pack & soc_packages[i].pack_mask))
108 return soc_packages[i].name;
109 }
110
111 return "Unknown";
112}
113
114static const char *socinfo_to_soc_id(u32 socinfo)
115{
116 unsigned int id = socinfo_to_major(socinfo);
117 int i;
118
119 for (i = 0 ; i < ARRAY_SIZE(soc_ids) ; ++i) {
120 if (soc_ids[i].id == id)
121 return soc_ids[i].name;
122 }
123
124 return "Unknown";
125}
126
127static void print_board_model(void)
128{
129 const char *model;
130 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
131 printf("Model: %s\n", model ? model : "Unknown");
132}
133
Stefan Agnercf47c0e2020-11-27 17:28:20 +0100134static unsigned int get_socinfo(void)
Julien Massonf41d7232019-03-25 11:55:29 +0100135{
136 struct regmap *regmap;
137 int nodeoffset, ret;
138 ofnode node;
139 unsigned int socinfo;
140
141 /* find the offset of compatible node */
142 nodeoffset = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
143 "amlogic,meson-gx-ao-secure");
144 if (nodeoffset < 0)
145 return 0;
146
147 /* check if chip-id is available */
148 if (!fdt_getprop(gd->fdt_blob, nodeoffset, "amlogic,has-chip-id", NULL))
149 return 0;
150
151 /* get regmap from the syscon node */
152 node = offset_to_ofnode(nodeoffset);
153 regmap = syscon_node_to_regmap(node);
154 if (IS_ERR(regmap)) {
155 printf("%s: failed to get regmap\n", __func__);
156 return 0;
157 }
158
159 /* read soc info */
160 ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo);
161 if (ret && !socinfo) {
162 printf("%s: invalid chipid value\n", __func__);
163 return 0;
164 }
165
Stefan Agnercf47c0e2020-11-27 17:28:20 +0100166 return socinfo;
167}
168
169int show_board_info(void)
170{
171 unsigned int socinfo;
172
Julien Massonf41d7232019-03-25 11:55:29 +0100173 /* print board information */
174 print_board_model();
Stefan Agnercf47c0e2020-11-27 17:28:20 +0100175
176 socinfo = get_socinfo();
177 if (!socinfo)
178 return 0;
179
Andreas Färber8e02efd2019-10-09 16:03:56 +0200180 printf("SoC: Amlogic Meson %s (%s) Revision %x:%x (%x:%x)\n",
Julien Massonf41d7232019-03-25 11:55:29 +0100181 socinfo_to_soc_id(socinfo),
182 socinfo_to_package_id(socinfo),
183 socinfo_to_major(socinfo),
184 socinfo_to_minor(socinfo),
185 socinfo_to_pack(socinfo),
186 socinfo_to_misc(socinfo));
187
188 return 0;
189}