board-info.c 4.1 KB

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