board-info.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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/global_data.h>
  9. #include <asm/io.h>
  10. #include <dm.h>
  11. #include <linux/bitfield.h>
  12. #include <regmap.h>
  13. #include <syscon.h>
  14. #include <linux/bitops.h>
  15. #include <linux/err.h>
  16. #define AO_SEC_SD_CFG8 0xe0
  17. #define AO_SEC_SOCINFO_OFFSET AO_SEC_SD_CFG8
  18. #define SOCINFO_MAJOR GENMASK(31, 24)
  19. #define SOCINFO_PACK GENMASK(23, 16)
  20. #define SOCINFO_MINOR GENMASK(15, 8)
  21. #define SOCINFO_MISC GENMASK(7, 0)
  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 },
  37. { "SM1", 0x2b },
  38. { "A1", 0x2c },
  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 },
  63. { "A311D", 0x29, 0x10, 0xf0 },
  64. { "S922X", 0x29, 0x40, 0xf0 },
  65. { "S905D3", 0x2b, 0x4, 0xf5 },
  66. { "S905X3", 0x2b, 0x5, 0xf5 },
  67. { "S905X3", 0x2b, 0x10, 0x3f },
  68. { "S905D3", 0x2b, 0x30, 0x3f },
  69. { "A113L", 0x2c, 0x0, 0xf8 },
  70. };
  71. DECLARE_GLOBAL_DATA_PTR;
  72. static inline unsigned int socinfo_to_major(u32 socinfo)
  73. {
  74. return FIELD_GET(SOCINFO_MAJOR, socinfo);
  75. }
  76. static inline unsigned int socinfo_to_minor(u32 socinfo)
  77. {
  78. return FIELD_GET(SOCINFO_MINOR, socinfo);
  79. }
  80. static inline unsigned int socinfo_to_pack(u32 socinfo)
  81. {
  82. return FIELD_GET(SOCINFO_PACK, socinfo);
  83. }
  84. static inline unsigned int socinfo_to_misc(u32 socinfo)
  85. {
  86. return FIELD_GET(SOCINFO_MISC, socinfo);
  87. }
  88. static const char *socinfo_to_package_id(u32 socinfo)
  89. {
  90. unsigned int pack = socinfo_to_pack(socinfo);
  91. unsigned int major = socinfo_to_major(socinfo);
  92. int i;
  93. for (i = 0 ; i < ARRAY_SIZE(soc_packages) ; ++i) {
  94. if (soc_packages[i].major_id == major &&
  95. soc_packages[i].pack_id ==
  96. (pack & soc_packages[i].pack_mask))
  97. return soc_packages[i].name;
  98. }
  99. return "Unknown";
  100. }
  101. static const char *socinfo_to_soc_id(u32 socinfo)
  102. {
  103. unsigned int id = socinfo_to_major(socinfo);
  104. int i;
  105. for (i = 0 ; i < ARRAY_SIZE(soc_ids) ; ++i) {
  106. if (soc_ids[i].id == id)
  107. return soc_ids[i].name;
  108. }
  109. return "Unknown";
  110. }
  111. static void print_board_model(void)
  112. {
  113. const char *model;
  114. model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
  115. printf("Model: %s\n", model ? model : "Unknown");
  116. }
  117. static unsigned int get_socinfo(void)
  118. {
  119. struct regmap *regmap;
  120. int nodeoffset, ret;
  121. ofnode node;
  122. unsigned int socinfo;
  123. /* find the offset of compatible node */
  124. nodeoffset = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
  125. "amlogic,meson-gx-ao-secure");
  126. if (nodeoffset < 0)
  127. return 0;
  128. /* check if chip-id is available */
  129. if (!fdt_getprop(gd->fdt_blob, nodeoffset, "amlogic,has-chip-id", NULL))
  130. return 0;
  131. /* get regmap from the syscon node */
  132. node = offset_to_ofnode(nodeoffset);
  133. regmap = syscon_node_to_regmap(node);
  134. if (IS_ERR(regmap)) {
  135. printf("%s: failed to get regmap\n", __func__);
  136. return 0;
  137. }
  138. /* read soc info */
  139. ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo);
  140. if (ret && !socinfo) {
  141. printf("%s: invalid chipid value\n", __func__);
  142. return 0;
  143. }
  144. return socinfo;
  145. }
  146. int show_board_info(void)
  147. {
  148. unsigned int socinfo;
  149. /* print board information */
  150. print_board_model();
  151. socinfo = get_socinfo();
  152. if (!socinfo)
  153. return 0;
  154. printf("SoC: Amlogic Meson %s (%s) Revision %x:%x (%x:%x)\n",
  155. socinfo_to_soc_id(socinfo),
  156. socinfo_to_package_id(socinfo),
  157. socinfo_to_major(socinfo),
  158. socinfo_to_minor(socinfo),
  159. socinfo_to_pack(socinfo),
  160. socinfo_to_misc(socinfo));
  161. return 0;
  162. }
  163. int meson_get_soc_rev(char *buff, size_t buff_len)
  164. {
  165. unsigned int socinfo;
  166. socinfo = get_socinfo();
  167. if (!socinfo)
  168. return -1;
  169. /* Write SoC info */
  170. return snprintf(buff, buff_len, "%x", socinfo_to_minor(socinfo));
  171. }