Julien Masson | f41d723 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 1 | // 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 Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Julien Masson | f41d723 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <dm.h> |
| 12 | #include <linux/bitfield.h> |
| 13 | #include <regmap.h> |
| 14 | #include <syscon.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Simon Glass | 61b29b8 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 16 | #include <linux/err.h> |
Julien Masson | f41d723 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 17 | |
| 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 | |
| 26 | static 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 Armstrong | dabd6a9 | 2019-10-11 17:33:51 +0200 | [diff] [blame] | 41 | { "SM1", 0x2b }, |
Neil Armstrong | b6a71e2 | 2020-11-09 14:30:01 +0100 | [diff] [blame] | 42 | { "A1", 0x2c }, |
Julien Masson | f41d723 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | static 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 }, |
| 67 | { "S905X2", 0x28, 0x40, 0xf0 }, |
Andreas Färber | 57212ff | 2019-10-09 16:03:57 +0200 | [diff] [blame] | 68 | { "A311D", 0x29, 0x10, 0xf0 }, |
Julien Masson | f41d723 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 69 | { "S922X", 0x29, 0x40, 0xf0 }, |
Neil Armstrong | b6a71e2 | 2020-11-09 14:30:01 +0100 | [diff] [blame] | 70 | { "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 Masson | f41d723 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | DECLARE_GLOBAL_DATA_PTR; |
| 78 | |
| 79 | static inline unsigned int socinfo_to_major(u32 socinfo) |
| 80 | { |
| 81 | return FIELD_GET(SOCINFO_MAJOR, socinfo); |
| 82 | } |
| 83 | |
| 84 | static inline unsigned int socinfo_to_minor(u32 socinfo) |
| 85 | { |
| 86 | return FIELD_GET(SOCINFO_MINOR, socinfo); |
| 87 | } |
| 88 | |
| 89 | static inline unsigned int socinfo_to_pack(u32 socinfo) |
| 90 | { |
| 91 | return FIELD_GET(SOCINFO_PACK, socinfo); |
| 92 | } |
| 93 | |
| 94 | static inline unsigned int socinfo_to_misc(u32 socinfo) |
| 95 | { |
| 96 | return FIELD_GET(SOCINFO_MISC, socinfo); |
| 97 | } |
| 98 | |
| 99 | static 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 | |
| 115 | static 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 | |
| 128 | static void print_board_model(void) |
| 129 | { |
| 130 | const char *model; |
| 131 | model = fdt_getprop(gd->fdt_blob, 0, "model", NULL); |
| 132 | printf("Model: %s\n", model ? model : "Unknown"); |
| 133 | } |
| 134 | |
Stefan Agner | cf47c0e | 2020-11-27 17:28:20 +0100 | [diff] [blame] | 135 | static unsigned int get_socinfo(void) |
Julien Masson | f41d723 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 136 | { |
| 137 | struct regmap *regmap; |
| 138 | int nodeoffset, ret; |
| 139 | ofnode node; |
| 140 | unsigned int socinfo; |
| 141 | |
| 142 | /* find the offset of compatible node */ |
| 143 | nodeoffset = fdt_node_offset_by_compatible(gd->fdt_blob, -1, |
| 144 | "amlogic,meson-gx-ao-secure"); |
| 145 | if (nodeoffset < 0) |
| 146 | return 0; |
| 147 | |
| 148 | /* check if chip-id is available */ |
| 149 | if (!fdt_getprop(gd->fdt_blob, nodeoffset, "amlogic,has-chip-id", NULL)) |
| 150 | return 0; |
| 151 | |
| 152 | /* get regmap from the syscon node */ |
| 153 | node = offset_to_ofnode(nodeoffset); |
| 154 | regmap = syscon_node_to_regmap(node); |
| 155 | if (IS_ERR(regmap)) { |
| 156 | printf("%s: failed to get regmap\n", __func__); |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | /* read soc info */ |
| 161 | ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo); |
| 162 | if (ret && !socinfo) { |
| 163 | printf("%s: invalid chipid value\n", __func__); |
| 164 | return 0; |
| 165 | } |
| 166 | |
Stefan Agner | cf47c0e | 2020-11-27 17:28:20 +0100 | [diff] [blame] | 167 | return socinfo; |
| 168 | } |
| 169 | |
| 170 | int show_board_info(void) |
| 171 | { |
| 172 | unsigned int socinfo; |
| 173 | |
Julien Masson | f41d723 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 174 | /* print board information */ |
| 175 | print_board_model(); |
Stefan Agner | cf47c0e | 2020-11-27 17:28:20 +0100 | [diff] [blame] | 176 | |
| 177 | socinfo = get_socinfo(); |
| 178 | if (!socinfo) |
| 179 | return 0; |
| 180 | |
Andreas Färber | 8e02efd | 2019-10-09 16:03:56 +0200 | [diff] [blame] | 181 | printf("SoC: Amlogic Meson %s (%s) Revision %x:%x (%x:%x)\n", |
Julien Masson | f41d723 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 182 | socinfo_to_soc_id(socinfo), |
| 183 | socinfo_to_package_id(socinfo), |
| 184 | socinfo_to_major(socinfo), |
| 185 | socinfo_to_minor(socinfo), |
| 186 | socinfo_to_pack(socinfo), |
| 187 | socinfo_to_misc(socinfo)); |
| 188 | |
| 189 | return 0; |
| 190 | } |
Pascal Vizeli | d42e796 | 2020-11-27 17:28:21 +0100 | [diff] [blame] | 191 | |
| 192 | int meson_get_soc_rev(char *buff, size_t buff_len) |
| 193 | { |
| 194 | unsigned int socinfo; |
| 195 | |
| 196 | socinfo = get_socinfo(); |
| 197 | if (!socinfo) |
| 198 | return -1; |
| 199 | |
| 200 | /* Write SoC info */ |
| 201 | return snprintf(buff, buff_len, "%x", socinfo_to_minor(socinfo)); |
| 202 | } |