aspeed-socinfo.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. /* AST2700 */
  29. { "AST2750", 0x06000003 },
  30. { "AST2700", 0x06000103 },
  31. { "AST2720", 0x06000203 },
  32. };
  33. static const char *siliconid_to_name(u32 siliconid)
  34. {
  35. unsigned int id = siliconid & 0xff00ffff;
  36. unsigned int i;
  37. for (i = 0 ; i < ARRAY_SIZE(rev_table) ; ++i) {
  38. if ((rev_table[i].id & 0xff00ffff) == id)
  39. return rev_table[i].name;
  40. }
  41. return "Unknown";
  42. }
  43. static const char *siliconid_to_rev(u32 siliconid)
  44. {
  45. unsigned int rev = (siliconid >> 16) & 0xff;
  46. unsigned int gen = (siliconid >> 24) & 0xff;
  47. if (gen < 0x5) {
  48. /* AST2500 and below */
  49. switch (rev) {
  50. case 0:
  51. return "A0";
  52. case 1:
  53. return "A1";
  54. case 3:
  55. return "A2";
  56. }
  57. } else {
  58. /* AST2600 */
  59. switch (rev) {
  60. case 0:
  61. return "A0";
  62. case 1:
  63. return "A1";
  64. case 2:
  65. return "A2";
  66. case 3:
  67. return "A3";
  68. }
  69. }
  70. return "??";
  71. }
  72. static int __init aspeed_socinfo_init(void)
  73. {
  74. struct soc_device_attribute *attrs;
  75. struct soc_device *soc_dev;
  76. struct device_node *np;
  77. void __iomem *reg;
  78. bool has_chipid = false;
  79. u32 siliconid;
  80. u32 chipid[2];
  81. const char *machine = NULL;
  82. np = of_find_compatible_node(NULL, NULL, "aspeed,silicon-id");
  83. if (!of_device_is_available(np)) {
  84. of_node_put(np);
  85. return -ENODEV;
  86. }
  87. reg = of_iomap(np, 0);
  88. if (!reg) {
  89. of_node_put(np);
  90. return -ENODEV;
  91. }
  92. siliconid = readl(reg);
  93. iounmap(reg);
  94. /* This is optional, the ast2400 does not have it */
  95. reg = of_iomap(np, 1);
  96. if (reg) {
  97. has_chipid = true;
  98. chipid[0] = readl(reg);
  99. chipid[1] = readl(reg + 4);
  100. iounmap(reg);
  101. }
  102. of_node_put(np);
  103. attrs = kzalloc_obj(*attrs);
  104. if (!attrs)
  105. return -ENODEV;
  106. /*
  107. * Machine: Romulus BMC
  108. * Family: AST2500
  109. * Revision: A1
  110. * SoC ID: raw silicon revision id
  111. * Serial Number: 64-bit chipid
  112. */
  113. np = of_find_node_by_path("/");
  114. of_property_read_string(np, "model", &machine);
  115. if (machine)
  116. attrs->machine = kstrdup(machine, GFP_KERNEL);
  117. of_node_put(np);
  118. attrs->family = siliconid_to_name(siliconid);
  119. attrs->revision = siliconid_to_rev(siliconid);
  120. attrs->soc_id = kasprintf(GFP_KERNEL, "%08x", siliconid);
  121. if (has_chipid)
  122. attrs->serial_number = kasprintf(GFP_KERNEL, "%08x%08x",
  123. chipid[1], chipid[0]);
  124. soc_dev = soc_device_register(attrs);
  125. if (IS_ERR(soc_dev)) {
  126. kfree(attrs->machine);
  127. kfree(attrs->soc_id);
  128. kfree(attrs->serial_number);
  129. kfree(attrs);
  130. return PTR_ERR(soc_dev);
  131. }
  132. pr_info("ASPEED %s rev %s (%s)\n",
  133. attrs->family,
  134. attrs->revision,
  135. attrs->soc_id);
  136. return 0;
  137. }
  138. early_initcall(aspeed_socinfo_init);