blob: b4058f593234e940fc2c00b82cdf9bd758cef567 [file] [log] [blame]
Julien Masson90f8d492019-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
Simon Glass97589732020-05-10 11:40:02 -06007#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06008#include <asm/global_data.h>
Julien Masson90f8d492019-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 Glass4dcacfc2020-05-10 11:40:13 -060014#include <linux/bitops.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070015#include <linux/err.h>
Julien Masson90f8d492019-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 Armstrong319600b2019-10-11 17:33:51 +020040 { "SM1", 0x2b },
Neil Armstrong507262f2020-11-09 14:30:01 +010041 { "A1", 0x2c },
Julien Masson90f8d492019-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 },
Christian Hewitt26773472021-08-20 02:18:36 +000066 { "S905Y2", 0x28, 0x30, 0xf0 },
Julien Masson90f8d492019-03-25 11:55:29 +010067 { "S905X2", 0x28, 0x40, 0xf0 },
Andreas Färberb9fe9ef2019-10-09 16:03:57 +020068 { "A311D", 0x29, 0x10, 0xf0 },
Julien Masson90f8d492019-03-25 11:55:29 +010069 { "S922X", 0x29, 0x40, 0xf0 },
Neil Armstrong507262f2020-11-09 14:30:01 +010070 { "S905D3", 0x2b, 0x4, 0xf5 },
71 { "S905X3", 0x2b, 0x5, 0xf5 },
72 { "S905X3", 0x2b, 0x10, 0x3f },
73 { "S905D3", 0x2b, 0x30, 0x3f },
74 { "A113L", 0x2c, 0x0, 0xf8 },
Julien Masson90f8d492019-03-25 11:55:29 +010075};
76
77DECLARE_GLOBAL_DATA_PTR;
78
79static inline unsigned int socinfo_to_major(u32 socinfo)
80{
81 return FIELD_GET(SOCINFO_MAJOR, socinfo);
82}
83
84static inline unsigned int socinfo_to_minor(u32 socinfo)
85{
86 return FIELD_GET(SOCINFO_MINOR, socinfo);
87}
88
89static inline unsigned int socinfo_to_pack(u32 socinfo)
90{
91 return FIELD_GET(SOCINFO_PACK, socinfo);
92}
93
94static inline unsigned int socinfo_to_misc(u32 socinfo)
95{
96 return FIELD_GET(SOCINFO_MISC, socinfo);
97}
98
99static const char *socinfo_to_package_id(u32 socinfo)
100{
101 unsigned int pack = socinfo_to_pack(socinfo);
102 unsigned int major = socinfo_to_major(socinfo);
103 int i;
104
105 for (i = 0 ; i < ARRAY_SIZE(soc_packages) ; ++i) {
106 if (soc_packages[i].major_id == major &&
107 soc_packages[i].pack_id ==
108 (pack & soc_packages[i].pack_mask))
109 return soc_packages[i].name;
110 }
111
112 return "Unknown";
113}
114
115static const char *socinfo_to_soc_id(u32 socinfo)
116{
117 unsigned int id = socinfo_to_major(socinfo);
118 int i;
119
120 for (i = 0 ; i < ARRAY_SIZE(soc_ids) ; ++i) {
121 if (soc_ids[i].id == id)
122 return soc_ids[i].name;
123 }
124
125 return "Unknown";
126}
127
Stefan Agner5ef07f02020-11-27 17:28:20 +0100128static unsigned int get_socinfo(void)
Julien Masson90f8d492019-03-25 11:55:29 +0100129{
130 struct regmap *regmap;
131 int nodeoffset, ret;
132 ofnode node;
133 unsigned int socinfo;
134
135 /* find the offset of compatible node */
136 nodeoffset = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
137 "amlogic,meson-gx-ao-secure");
138 if (nodeoffset < 0)
139 return 0;
140
141 /* check if chip-id is available */
142 if (!fdt_getprop(gd->fdt_blob, nodeoffset, "amlogic,has-chip-id", NULL))
143 return 0;
144
145 /* get regmap from the syscon node */
146 node = offset_to_ofnode(nodeoffset);
147 regmap = syscon_node_to_regmap(node);
148 if (IS_ERR(regmap)) {
149 printf("%s: failed to get regmap\n", __func__);
150 return 0;
151 }
152
153 /* read soc info */
154 ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo);
155 if (ret && !socinfo) {
156 printf("%s: invalid chipid value\n", __func__);
157 return 0;
158 }
159
Stefan Agner5ef07f02020-11-27 17:28:20 +0100160 return socinfo;
161}
162
Simon Glassd41f7aa2023-11-12 19:58:22 -0700163int checkboard(void)
Stefan Agner5ef07f02020-11-27 17:28:20 +0100164{
165 unsigned int socinfo;
166
Stefan Agner5ef07f02020-11-27 17:28:20 +0100167 socinfo = get_socinfo();
168 if (!socinfo)
169 return 0;
170
Andreas Färbere9763db2019-10-09 16:03:56 +0200171 printf("SoC: Amlogic Meson %s (%s) Revision %x:%x (%x:%x)\n",
Julien Masson90f8d492019-03-25 11:55:29 +0100172 socinfo_to_soc_id(socinfo),
173 socinfo_to_package_id(socinfo),
174 socinfo_to_major(socinfo),
175 socinfo_to_minor(socinfo),
176 socinfo_to_pack(socinfo),
177 socinfo_to_misc(socinfo));
178
179 return 0;
180}
Pascal Vizeli07168542020-11-27 17:28:21 +0100181
182int meson_get_soc_rev(char *buff, size_t buff_len)
183{
184 unsigned int socinfo;
185
186 socinfo = get_socinfo();
187 if (!socinfo)
188 return -1;
189
190 /* Write SoC info */
191 return snprintf(buff, buff_len, "%x", socinfo_to_minor(socinfo));
192}