aspeed-socinfo.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* Copyright 2019 IBM Corp. */
  3. #include <linux/io.h>
  4. #include <linux/of.h>
  5. #include <linux/of_address.h>
  6. #include <linux/of_platform.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/slab.h>
  9. #include <linux/sys_soc.h>
  10. static struct {
  11. const char *name;
  12. const u32 id;
  13. } const rev_table[] = {
  14. /* AST2400 */
  15. { "AST2400", 0x02000303 },
  16. { "AST1400", 0x02010103 },
  17. { "AST1250", 0x02010303 },
  18. /* AST2500 */
  19. { "AST2500", 0x04000303 },
  20. { "AST2510", 0x04000103 },
  21. { "AST2520", 0x04000203 },
  22. { "AST2530", 0x04000403 },
  23. /* AST2600 */
  24. { "AST2600", 0x05000303 },
  25. { "AST2620", 0x05010203 },
  26. { "AST2605", 0x05030103 },
  27. { "AST2625", 0x05030403 },
  28. };
  29. static const char *siliconid_to_name(u32 siliconid)
  30. {
  31. unsigned int id = siliconid & 0xff00ffff;
  32. unsigned int i;
  33. for (i = 0 ; i < ARRAY_SIZE(rev_table) ; ++i) {
  34. if (rev_table[i].id == id)
  35. return rev_table[i].name;
  36. }
  37. return "Unknown";
  38. }
  39. static const char *siliconid_to_rev(u32 siliconid)
  40. {
  41. unsigned int rev = (siliconid >> 16) & 0xff;
  42. unsigned int gen = (siliconid >> 24) & 0xff;
  43. if (gen < 0x5) {
  44. /* AST2500 and below */
  45. switch (rev) {
  46. case 0:
  47. return "A0";
  48. case 1:
  49. return "A1";
  50. case 3:
  51. return "A2";
  52. }
  53. } else {
  54. /* AST2600 */
  55. switch (rev) {
  56. case 0:
  57. return "A0";
  58. case 1:
  59. return "A1";
  60. case 2:
  61. return "A2";
  62. case 3:
  63. return "A3";
  64. }
  65. }
  66. return "??";
  67. }
  68. static int __init aspeed_socinfo_init(void)
  69. {
  70. struct soc_device_attribute *attrs;
  71. struct soc_device *soc_dev;
  72. struct device_node *np;
  73. void __iomem *reg;
  74. bool has_chipid = false;
  75. u32 siliconid;
  76. u32 chipid[2];
  77. const char *machine = NULL;
  78. np = of_find_compatible_node(NULL, NULL, "aspeed,silicon-id");
  79. if (!of_device_is_available(np)) {
  80. of_node_put(np);
  81. return -ENODEV;
  82. }
  83. reg = of_iomap(np, 0);
  84. if (!reg) {
  85. of_node_put(np);
  86. return -ENODEV;
  87. }
  88. siliconid = readl(reg);
  89. iounmap(reg);
  90. /* This is optional, the ast2400 does not have it */
  91. reg = of_iomap(np, 1);
  92. if (reg) {
  93. has_chipid = true;
  94. chipid[0] = readl(reg);
  95. chipid[1] = readl(reg + 4);
  96. iounmap(reg);
  97. }
  98. of_node_put(np);
  99. attrs = kzalloc(sizeof(*attrs), GFP_KERNEL);
  100. if (!attrs)
  101. return -ENODEV;
  102. /*
  103. * Machine: Romulus BMC
  104. * Family: AST2500
  105. * Revision: A1
  106. * SoC ID: raw silicon revision id
  107. * Serial Number: 64-bit chipid
  108. */
  109. np = of_find_node_by_path("/");
  110. of_property_read_string(np, "model", &machine);
  111. if (machine)
  112. attrs->machine = kstrdup(machine, GFP_KERNEL);
  113. of_node_put(np);
  114. attrs->family = siliconid_to_name(siliconid);
  115. attrs->revision = siliconid_to_rev(siliconid);
  116. attrs->soc_id = kasprintf(GFP_KERNEL, "%08x", siliconid);
  117. if (has_chipid)
  118. attrs->serial_number = kasprintf(GFP_KERNEL, "%08x%08x",
  119. chipid[1], chipid[0]);
  120. soc_dev = soc_device_register(attrs);
  121. if (IS_ERR(soc_dev)) {
  122. kfree(attrs->machine);
  123. kfree(attrs->soc_id);
  124. kfree(attrs->serial_number);
  125. kfree(attrs);
  126. return PTR_ERR(soc_dev);
  127. }
  128. pr_info("ASPEED %s rev %s (%s)\n",
  129. attrs->family,
  130. attrs->revision,
  131. attrs->soc_id);
  132. return 0;
  133. }
  134. early_initcall(aspeed_socinfo_init);