board-info.c 4.1 KB

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