blob: d51d9b8f064512aa5445f5bb47c5d6d53a095dcc [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
7#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Julien Masson90f8d492019-03-25 11:55:29 +010010#include <asm/io.h>
11#include <dm.h>
12#include <linux/bitfield.h>
13#include <regmap.h>
14#include <syscon.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060015#include <linux/bitops.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070016#include <linux/err.h>
Julien Masson90f8d492019-03-25 11:55:29 +010017
18#define AO_SEC_SD_CFG8 0xe0
19#define AO_SEC_SOCINFO_OFFSET AO_SEC_SD_CFG8
20
21#define SOCINFO_MAJOR GENMASK(31, 24)
22#define SOCINFO_PACK GENMASK(23, 16)
23#define SOCINFO_MINOR GENMASK(15, 8)
24#define SOCINFO_MISC GENMASK(7, 0)
25
26static const struct meson_gx_soc_id {
27 const char *name;
28 unsigned int id;
29} soc_ids[] = {
30 { "GXBB", 0x1f },
31 { "GXTVBB", 0x20 },
32 { "GXL", 0x21 },
33 { "GXM", 0x22 },
34 { "TXL", 0x23 },
35 { "TXLX", 0x24 },
36 { "AXG", 0x25 },
37 { "GXLX", 0x26 },
38 { "TXHD", 0x27 },
39 { "G12A", 0x28 },
40 { "G12B", 0x29 },
Neil Armstrong319600b2019-10-11 17:33:51 +020041 { "SM1", 0x2b },
Neil Armstrong507262f2020-11-09 14:30:01 +010042 { "A1", 0x2c },
Julien Masson90f8d492019-03-25 11:55:29 +010043};
44
45static const struct meson_gx_package_id {
46 const char *name;
47 unsigned int major_id;
48 unsigned int pack_id;
49 unsigned int pack_mask;
50} soc_packages[] = {
51 { "S905", 0x1f, 0, 0x20 }, /* pack_id != 0x20 */
52 { "S905H", 0x1f, 0x3, 0xf }, /* pack_id & 0xf == 0x3 */
53 { "S905M", 0x1f, 0x20, 0xf0 }, /* pack_id == 0x20 */
54 { "S905D", 0x21, 0, 0xf0 },
55 { "S905X", 0x21, 0x80, 0xf0 },
56 { "S905W", 0x21, 0xa0, 0xf0 },
57 { "S905L", 0x21, 0xc0, 0xf0 },
58 { "S905M2", 0x21, 0xe0, 0xf0 },
59 { "S805X", 0x21, 0x30, 0xf0 },
60 { "S805Y", 0x21, 0xb0, 0xf0 },
61 { "S912", 0x22, 0, 0x0 }, /* Only S912 is known for GXM */
62 { "962X", 0x24, 0x10, 0xf0 },
63 { "962E", 0x24, 0x20, 0xf0 },
64 { "A113X", 0x25, 0x37, 0xff },
65 { "A113D", 0x25, 0x22, 0xff },
66 { "S905D2", 0x28, 0x10, 0xf0 },
Christian Hewitt26773472021-08-20 02:18:36 +000067 { "S905Y2", 0x28, 0x30, 0xf0 },
Julien Masson90f8d492019-03-25 11:55:29 +010068 { "S905X2", 0x28, 0x40, 0xf0 },
Andreas Färberb9fe9ef2019-10-09 16:03:57 +020069 { "A311D", 0x29, 0x10, 0xf0 },
Julien Masson90f8d492019-03-25 11:55:29 +010070 { "S922X", 0x29, 0x40, 0xf0 },
Neil Armstrong507262f2020-11-09 14:30:01 +010071 { "S905D3", 0x2b, 0x4, 0xf5 },
72 { "S905X3", 0x2b, 0x5, 0xf5 },
73 { "S905X3", 0x2b, 0x10, 0x3f },
74 { "S905D3", 0x2b, 0x30, 0x3f },
75 { "A113L", 0x2c, 0x0, 0xf8 },
Julien Masson90f8d492019-03-25 11:55:29 +010076};
77
78DECLARE_GLOBAL_DATA_PTR;
79
80static inline unsigned int socinfo_to_major(u32 socinfo)
81{
82 return FIELD_GET(SOCINFO_MAJOR, socinfo);
83}
84
85static inline unsigned int socinfo_to_minor(u32 socinfo)
86{
87 return FIELD_GET(SOCINFO_MINOR, socinfo);
88}
89
90static inline unsigned int socinfo_to_pack(u32 socinfo)
91{
92 return FIELD_GET(SOCINFO_PACK, socinfo);
93}
94
95static inline unsigned int socinfo_to_misc(u32 socinfo)
96{
97 return FIELD_GET(SOCINFO_MISC, socinfo);
98}
99
100static const char *socinfo_to_package_id(u32 socinfo)
101{
102 unsigned int pack = socinfo_to_pack(socinfo);
103 unsigned int major = socinfo_to_major(socinfo);
104 int i;
105
106 for (i = 0 ; i < ARRAY_SIZE(soc_packages) ; ++i) {
107 if (soc_packages[i].major_id == major &&
108 soc_packages[i].pack_id ==
109 (pack & soc_packages[i].pack_mask))
110 return soc_packages[i].name;
111 }
112
113 return "Unknown";
114}
115
116static const char *socinfo_to_soc_id(u32 socinfo)
117{
118 unsigned int id = socinfo_to_major(socinfo);
119 int i;
120
121 for (i = 0 ; i < ARRAY_SIZE(soc_ids) ; ++i) {
122 if (soc_ids[i].id == id)
123 return soc_ids[i].name;
124 }
125
126 return "Unknown";
127}
128
Stefan Agner5ef07f02020-11-27 17:28:20 +0100129static unsigned int get_socinfo(void)
Julien Masson90f8d492019-03-25 11:55:29 +0100130{
131 struct regmap *regmap;
132 int nodeoffset, ret;
133 ofnode node;
134 unsigned int socinfo;
135
136 /* find the offset of compatible node */
137 nodeoffset = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
138 "amlogic,meson-gx-ao-secure");
139 if (nodeoffset < 0)
140 return 0;
141
142 /* check if chip-id is available */
143 if (!fdt_getprop(gd->fdt_blob, nodeoffset, "amlogic,has-chip-id", NULL))
144 return 0;
145
146 /* get regmap from the syscon node */
147 node = offset_to_ofnode(nodeoffset);
148 regmap = syscon_node_to_regmap(node);
149 if (IS_ERR(regmap)) {
150 printf("%s: failed to get regmap\n", __func__);
151 return 0;
152 }
153
154 /* read soc info */
155 ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo);
156 if (ret && !socinfo) {
157 printf("%s: invalid chipid value\n", __func__);
158 return 0;
159 }
160
Stefan Agner5ef07f02020-11-27 17:28:20 +0100161 return socinfo;
162}
163
Simon Glassd41f7aa2023-11-12 19:58:22 -0700164int checkboard(void)
Stefan Agner5ef07f02020-11-27 17:28:20 +0100165{
166 unsigned int socinfo;
167
Stefan Agner5ef07f02020-11-27 17:28:20 +0100168 socinfo = get_socinfo();
169 if (!socinfo)
170 return 0;
171
Andreas Färbere9763db2019-10-09 16:03:56 +0200172 printf("SoC: Amlogic Meson %s (%s) Revision %x:%x (%x:%x)\n",
Julien Masson90f8d492019-03-25 11:55:29 +0100173 socinfo_to_soc_id(socinfo),
174 socinfo_to_package_id(socinfo),
175 socinfo_to_major(socinfo),
176 socinfo_to_minor(socinfo),
177 socinfo_to_pack(socinfo),
178 socinfo_to_misc(socinfo));
179
180 return 0;
181}
Pascal Vizeli07168542020-11-27 17:28:21 +0100182
183int meson_get_soc_rev(char *buff, size_t buff_len)
184{
185 unsigned int socinfo;
186
187 socinfo = get_socinfo();
188 if (!socinfo)
189 return -1;
190
191 /* Write SoC info */
192 return snprintf(buff, buff_len, "%x", socinfo_to_minor(socinfo));
193}