blob: bfae0c36ea13023a8555d0bcd9e402d27e7c96c0 [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 Glass61b29b82020-02-03 07:36:15 -070014#include <linux/err.h>
Julien Massonf41d7232019-03-25 11:55:29 +010015
16#define AO_SEC_SD_CFG8 0xe0
17#define AO_SEC_SOCINFO_OFFSET AO_SEC_SD_CFG8
18
19#define SOCINFO_MAJOR GENMASK(31, 24)
20#define SOCINFO_PACK GENMASK(23, 16)
21#define SOCINFO_MINOR GENMASK(15, 8)
22#define SOCINFO_MISC GENMASK(7, 0)
23
24static const struct meson_gx_soc_id {
25 const char *name;
26 unsigned int id;
27} soc_ids[] = {
28 { "GXBB", 0x1f },
29 { "GXTVBB", 0x20 },
30 { "GXL", 0x21 },
31 { "GXM", 0x22 },
32 { "TXL", 0x23 },
33 { "TXLX", 0x24 },
34 { "AXG", 0x25 },
35 { "GXLX", 0x26 },
36 { "TXHD", 0x27 },
37 { "G12A", 0x28 },
38 { "G12B", 0x29 },
Neil Armstrongdabd6a92019-10-11 17:33:51 +020039 { "SM1", 0x2b },
Julien Massonf41d7232019-03-25 11:55:29 +010040};
41
42static const struct meson_gx_package_id {
43 const char *name;
44 unsigned int major_id;
45 unsigned int pack_id;
46 unsigned int pack_mask;
47} soc_packages[] = {
48 { "S905", 0x1f, 0, 0x20 }, /* pack_id != 0x20 */
49 { "S905H", 0x1f, 0x3, 0xf }, /* pack_id & 0xf == 0x3 */
50 { "S905M", 0x1f, 0x20, 0xf0 }, /* pack_id == 0x20 */
51 { "S905D", 0x21, 0, 0xf0 },
52 { "S905X", 0x21, 0x80, 0xf0 },
53 { "S905W", 0x21, 0xa0, 0xf0 },
54 { "S905L", 0x21, 0xc0, 0xf0 },
55 { "S905M2", 0x21, 0xe0, 0xf0 },
56 { "S805X", 0x21, 0x30, 0xf0 },
57 { "S805Y", 0x21, 0xb0, 0xf0 },
58 { "S912", 0x22, 0, 0x0 }, /* Only S912 is known for GXM */
59 { "962X", 0x24, 0x10, 0xf0 },
60 { "962E", 0x24, 0x20, 0xf0 },
61 { "A113X", 0x25, 0x37, 0xff },
62 { "A113D", 0x25, 0x22, 0xff },
63 { "S905D2", 0x28, 0x10, 0xf0 },
64 { "S905X2", 0x28, 0x40, 0xf0 },
Andreas Färber57212ff2019-10-09 16:03:57 +020065 { "A311D", 0x29, 0x10, 0xf0 },
Julien Massonf41d7232019-03-25 11:55:29 +010066 { "S922X", 0x29, 0x40, 0xf0 },
Neil Armstrongdabd6a92019-10-11 17:33:51 +020067 { "S905X3", 0x2b, 0x5, 0xf },
Julien Massonf41d7232019-03-25 11:55:29 +010068};
69
70DECLARE_GLOBAL_DATA_PTR;
71
72static inline unsigned int socinfo_to_major(u32 socinfo)
73{
74 return FIELD_GET(SOCINFO_MAJOR, socinfo);
75}
76
77static inline unsigned int socinfo_to_minor(u32 socinfo)
78{
79 return FIELD_GET(SOCINFO_MINOR, socinfo);
80}
81
82static inline unsigned int socinfo_to_pack(u32 socinfo)
83{
84 return FIELD_GET(SOCINFO_PACK, socinfo);
85}
86
87static inline unsigned int socinfo_to_misc(u32 socinfo)
88{
89 return FIELD_GET(SOCINFO_MISC, socinfo);
90}
91
92static const char *socinfo_to_package_id(u32 socinfo)
93{
94 unsigned int pack = socinfo_to_pack(socinfo);
95 unsigned int major = socinfo_to_major(socinfo);
96 int i;
97
98 for (i = 0 ; i < ARRAY_SIZE(soc_packages) ; ++i) {
99 if (soc_packages[i].major_id == major &&
100 soc_packages[i].pack_id ==
101 (pack & soc_packages[i].pack_mask))
102 return soc_packages[i].name;
103 }
104
105 return "Unknown";
106}
107
108static const char *socinfo_to_soc_id(u32 socinfo)
109{
110 unsigned int id = socinfo_to_major(socinfo);
111 int i;
112
113 for (i = 0 ; i < ARRAY_SIZE(soc_ids) ; ++i) {
114 if (soc_ids[i].id == id)
115 return soc_ids[i].name;
116 }
117
118 return "Unknown";
119}
120
121static void print_board_model(void)
122{
123 const char *model;
124 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
125 printf("Model: %s\n", model ? model : "Unknown");
126}
127
128int show_board_info(void)
129{
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
160 /* print board information */
161 print_board_model();
Andreas Färber8e02efd2019-10-09 16:03:56 +0200162 printf("SoC: Amlogic Meson %s (%s) Revision %x:%x (%x:%x)\n",
Julien Massonf41d7232019-03-25 11:55:29 +0100163 socinfo_to_soc_id(socinfo),
164 socinfo_to_package_id(socinfo),
165 socinfo_to_major(socinfo),
166 socinfo_to_minor(socinfo),
167 socinfo_to_pack(socinfo),
168 socinfo_to_misc(socinfo));
169
170 return 0;
171}