Julien Masson | 90f8d49 | 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> |
| 8 | #include <asm/io.h> |
| 9 | #include <dm.h> |
| 10 | #include <linux/bitfield.h> |
| 11 | #include <regmap.h> |
| 12 | #include <syscon.h> |
| 13 | |
| 14 | #define AO_SEC_SD_CFG8 0xe0 |
| 15 | #define AO_SEC_SOCINFO_OFFSET AO_SEC_SD_CFG8 |
| 16 | |
| 17 | #define SOCINFO_MAJOR GENMASK(31, 24) |
| 18 | #define SOCINFO_PACK GENMASK(23, 16) |
| 19 | #define SOCINFO_MINOR GENMASK(15, 8) |
| 20 | #define SOCINFO_MISC GENMASK(7, 0) |
| 21 | |
| 22 | static const struct meson_gx_soc_id { |
| 23 | const char *name; |
| 24 | unsigned int id; |
| 25 | } soc_ids[] = { |
| 26 | { "GXBB", 0x1f }, |
| 27 | { "GXTVBB", 0x20 }, |
| 28 | { "GXL", 0x21 }, |
| 29 | { "GXM", 0x22 }, |
| 30 | { "TXL", 0x23 }, |
| 31 | { "TXLX", 0x24 }, |
| 32 | { "AXG", 0x25 }, |
| 33 | { "GXLX", 0x26 }, |
| 34 | { "TXHD", 0x27 }, |
| 35 | { "G12A", 0x28 }, |
| 36 | { "G12B", 0x29 }, |
Neil Armstrong | 319600b | 2019-10-11 17:33:51 +0200 | [diff] [blame] | 37 | { "SM1", 0x2b }, |
Julien Masson | 90f8d49 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | static const struct meson_gx_package_id { |
| 41 | const char *name; |
| 42 | unsigned int major_id; |
| 43 | unsigned int pack_id; |
| 44 | unsigned int pack_mask; |
| 45 | } soc_packages[] = { |
| 46 | { "S905", 0x1f, 0, 0x20 }, /* pack_id != 0x20 */ |
| 47 | { "S905H", 0x1f, 0x3, 0xf }, /* pack_id & 0xf == 0x3 */ |
| 48 | { "S905M", 0x1f, 0x20, 0xf0 }, /* pack_id == 0x20 */ |
| 49 | { "S905D", 0x21, 0, 0xf0 }, |
| 50 | { "S905X", 0x21, 0x80, 0xf0 }, |
| 51 | { "S905W", 0x21, 0xa0, 0xf0 }, |
| 52 | { "S905L", 0x21, 0xc0, 0xf0 }, |
| 53 | { "S905M2", 0x21, 0xe0, 0xf0 }, |
| 54 | { "S805X", 0x21, 0x30, 0xf0 }, |
| 55 | { "S805Y", 0x21, 0xb0, 0xf0 }, |
| 56 | { "S912", 0x22, 0, 0x0 }, /* Only S912 is known for GXM */ |
| 57 | { "962X", 0x24, 0x10, 0xf0 }, |
| 58 | { "962E", 0x24, 0x20, 0xf0 }, |
| 59 | { "A113X", 0x25, 0x37, 0xff }, |
| 60 | { "A113D", 0x25, 0x22, 0xff }, |
| 61 | { "S905D2", 0x28, 0x10, 0xf0 }, |
| 62 | { "S905X2", 0x28, 0x40, 0xf0 }, |
Andreas Färber | b9fe9ef | 2019-10-09 16:03:57 +0200 | [diff] [blame] | 63 | { "A311D", 0x29, 0x10, 0xf0 }, |
Julien Masson | 90f8d49 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 64 | { "S922X", 0x29, 0x40, 0xf0 }, |
Neil Armstrong | 319600b | 2019-10-11 17:33:51 +0200 | [diff] [blame] | 65 | { "S905X3", 0x2b, 0x5, 0xf }, |
Julien Masson | 90f8d49 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | DECLARE_GLOBAL_DATA_PTR; |
| 69 | |
| 70 | static inline unsigned int socinfo_to_major(u32 socinfo) |
| 71 | { |
| 72 | return FIELD_GET(SOCINFO_MAJOR, socinfo); |
| 73 | } |
| 74 | |
| 75 | static inline unsigned int socinfo_to_minor(u32 socinfo) |
| 76 | { |
| 77 | return FIELD_GET(SOCINFO_MINOR, socinfo); |
| 78 | } |
| 79 | |
| 80 | static inline unsigned int socinfo_to_pack(u32 socinfo) |
| 81 | { |
| 82 | return FIELD_GET(SOCINFO_PACK, socinfo); |
| 83 | } |
| 84 | |
| 85 | static inline unsigned int socinfo_to_misc(u32 socinfo) |
| 86 | { |
| 87 | return FIELD_GET(SOCINFO_MISC, socinfo); |
| 88 | } |
| 89 | |
| 90 | static const char *socinfo_to_package_id(u32 socinfo) |
| 91 | { |
| 92 | unsigned int pack = socinfo_to_pack(socinfo); |
| 93 | unsigned int major = socinfo_to_major(socinfo); |
| 94 | int i; |
| 95 | |
| 96 | for (i = 0 ; i < ARRAY_SIZE(soc_packages) ; ++i) { |
| 97 | if (soc_packages[i].major_id == major && |
| 98 | soc_packages[i].pack_id == |
| 99 | (pack & soc_packages[i].pack_mask)) |
| 100 | return soc_packages[i].name; |
| 101 | } |
| 102 | |
| 103 | return "Unknown"; |
| 104 | } |
| 105 | |
| 106 | static const char *socinfo_to_soc_id(u32 socinfo) |
| 107 | { |
| 108 | unsigned int id = socinfo_to_major(socinfo); |
| 109 | int i; |
| 110 | |
| 111 | for (i = 0 ; i < ARRAY_SIZE(soc_ids) ; ++i) { |
| 112 | if (soc_ids[i].id == id) |
| 113 | return soc_ids[i].name; |
| 114 | } |
| 115 | |
| 116 | return "Unknown"; |
| 117 | } |
| 118 | |
| 119 | static void print_board_model(void) |
| 120 | { |
| 121 | const char *model; |
| 122 | model = fdt_getprop(gd->fdt_blob, 0, "model", NULL); |
| 123 | printf("Model: %s\n", model ? model : "Unknown"); |
| 124 | } |
| 125 | |
| 126 | int show_board_info(void) |
| 127 | { |
| 128 | struct regmap *regmap; |
| 129 | int nodeoffset, ret; |
| 130 | ofnode node; |
| 131 | unsigned int socinfo; |
| 132 | |
| 133 | /* find the offset of compatible node */ |
| 134 | nodeoffset = fdt_node_offset_by_compatible(gd->fdt_blob, -1, |
| 135 | "amlogic,meson-gx-ao-secure"); |
| 136 | if (nodeoffset < 0) |
| 137 | return 0; |
| 138 | |
| 139 | /* check if chip-id is available */ |
| 140 | if (!fdt_getprop(gd->fdt_blob, nodeoffset, "amlogic,has-chip-id", NULL)) |
| 141 | return 0; |
| 142 | |
| 143 | /* get regmap from the syscon node */ |
| 144 | node = offset_to_ofnode(nodeoffset); |
| 145 | regmap = syscon_node_to_regmap(node); |
| 146 | if (IS_ERR(regmap)) { |
| 147 | printf("%s: failed to get regmap\n", __func__); |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | /* read soc info */ |
| 152 | ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo); |
| 153 | if (ret && !socinfo) { |
| 154 | printf("%s: invalid chipid value\n", __func__); |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | /* print board information */ |
| 159 | print_board_model(); |
Andreas Färber | e9763db | 2019-10-09 16:03:56 +0200 | [diff] [blame] | 160 | printf("SoC: Amlogic Meson %s (%s) Revision %x:%x (%x:%x)\n", |
Julien Masson | 90f8d49 | 2019-03-25 11:55:29 +0100 | [diff] [blame] | 161 | socinfo_to_soc_id(socinfo), |
| 162 | socinfo_to_package_id(socinfo), |
| 163 | socinfo_to_major(socinfo), |
| 164 | socinfo_to_minor(socinfo), |
| 165 | socinfo_to_pack(socinfo), |
| 166 | socinfo_to_misc(socinfo)); |
| 167 | |
| 168 | return 0; |
| 169 | } |