meson-mx-socinfo.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (c) 2017 Martin Blumenstingl <martin.blumenstingl@googlemail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <linux/io.h>
  7. #include <linux/of.h>
  8. #include <linux/of_address.h>
  9. #include <linux/of_platform.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/slab.h>
  12. #include <linux/sys_soc.h>
  13. #include <linux/bitfield.h>
  14. #include <linux/regmap.h>
  15. #include <linux/mfd/syscon.h>
  16. #define MESON_SOCINFO_MAJOR_VER_MESON6 0x16
  17. #define MESON_SOCINFO_MAJOR_VER_MESON8 0x19
  18. #define MESON_SOCINFO_MAJOR_VER_MESON8B 0x1b
  19. #define MESON_MX_ASSIST_HW_REV 0x14c
  20. #define MESON_MX_ANALOG_TOP_METAL_REVISION 0x0
  21. #define MESON_MX_BOOTROM_MISC_VER 0x4
  22. static const char *meson_mx_socinfo_revision(unsigned int major_ver,
  23. unsigned int misc_ver,
  24. unsigned int metal_rev)
  25. {
  26. unsigned int minor_ver;
  27. switch (major_ver) {
  28. case MESON_SOCINFO_MAJOR_VER_MESON6:
  29. minor_ver = 0xa;
  30. break;
  31. case MESON_SOCINFO_MAJOR_VER_MESON8:
  32. if (metal_rev == 0x11111112)
  33. major_ver = 0x1d;
  34. if (metal_rev == 0x11111111 || metal_rev == 0x11111112)
  35. minor_ver = 0xa;
  36. else if (metal_rev == 0x11111113)
  37. minor_ver = 0xb;
  38. else if (metal_rev == 0x11111133)
  39. minor_ver = 0xc;
  40. else
  41. minor_ver = 0xd;
  42. break;
  43. case MESON_SOCINFO_MAJOR_VER_MESON8B:
  44. if (metal_rev == 0x11111111)
  45. minor_ver = 0xa;
  46. else
  47. minor_ver = 0xb;
  48. break;
  49. default:
  50. minor_ver = 0x0;
  51. break;
  52. }
  53. return kasprintf(GFP_KERNEL, "Rev%X (%x - 0:%X)", minor_ver, major_ver,
  54. misc_ver);
  55. }
  56. static const char *meson_mx_socinfo_soc_id(unsigned int major_ver,
  57. unsigned int metal_rev)
  58. {
  59. const char *soc_id;
  60. switch (major_ver) {
  61. case MESON_SOCINFO_MAJOR_VER_MESON6:
  62. soc_id = "Meson6 (AML8726-MX)";
  63. break;
  64. case MESON_SOCINFO_MAJOR_VER_MESON8:
  65. if (metal_rev == 0x11111112)
  66. soc_id = "Meson8m2 (S812)";
  67. else
  68. soc_id = "Meson8 (S802)";
  69. break;
  70. case MESON_SOCINFO_MAJOR_VER_MESON8B:
  71. soc_id = "Meson8b (S805)";
  72. break;
  73. default:
  74. soc_id = "Unknown";
  75. break;
  76. }
  77. return kstrdup_const(soc_id, GFP_KERNEL);
  78. }
  79. static const struct of_device_id meson_mx_socinfo_analog_top_ids[] = {
  80. { .compatible = "amlogic,meson8-analog-top", },
  81. { .compatible = "amlogic,meson8b-analog-top", },
  82. { /* sentinel */ }
  83. };
  84. static int __init meson_mx_socinfo_init(void)
  85. {
  86. struct soc_device_attribute *soc_dev_attr;
  87. struct soc_device *soc_dev;
  88. struct device_node *np;
  89. struct regmap *assist_regmap, *bootrom_regmap, *analog_top_regmap;
  90. unsigned int major_ver, misc_ver, metal_rev = 0;
  91. int ret;
  92. assist_regmap =
  93. syscon_regmap_lookup_by_compatible("amlogic,meson-mx-assist");
  94. if (IS_ERR(assist_regmap))
  95. return PTR_ERR(assist_regmap);
  96. bootrom_regmap =
  97. syscon_regmap_lookup_by_compatible("amlogic,meson-mx-bootrom");
  98. if (IS_ERR(bootrom_regmap))
  99. return PTR_ERR(bootrom_regmap);
  100. np = of_find_matching_node(NULL, meson_mx_socinfo_analog_top_ids);
  101. if (np) {
  102. analog_top_regmap = syscon_node_to_regmap(np);
  103. if (IS_ERR(analog_top_regmap))
  104. return PTR_ERR(analog_top_regmap);
  105. ret = regmap_read(analog_top_regmap,
  106. MESON_MX_ANALOG_TOP_METAL_REVISION,
  107. &metal_rev);
  108. if (ret)
  109. return ret;
  110. }
  111. ret = regmap_read(assist_regmap, MESON_MX_ASSIST_HW_REV, &major_ver);
  112. if (ret < 0)
  113. return ret;
  114. ret = regmap_read(bootrom_regmap, MESON_MX_BOOTROM_MISC_VER,
  115. &misc_ver);
  116. if (ret < 0)
  117. return ret;
  118. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  119. if (!soc_dev_attr)
  120. return -ENODEV;
  121. soc_dev_attr->family = "Amlogic Meson";
  122. np = of_find_node_by_path("/");
  123. of_property_read_string(np, "model", &soc_dev_attr->machine);
  124. of_node_put(np);
  125. soc_dev_attr->revision = meson_mx_socinfo_revision(major_ver, misc_ver,
  126. metal_rev);
  127. soc_dev_attr->soc_id = meson_mx_socinfo_soc_id(major_ver, metal_rev);
  128. soc_dev = soc_device_register(soc_dev_attr);
  129. if (IS_ERR(soc_dev)) {
  130. kfree_const(soc_dev_attr->revision);
  131. kfree_const(soc_dev_attr->soc_id);
  132. kfree(soc_dev_attr);
  133. return PTR_ERR(soc_dev);
  134. }
  135. dev_info(soc_device_to_device(soc_dev), "Amlogic %s %s detected\n",
  136. soc_dev_attr->soc_id, soc_dev_attr->revision);
  137. return 0;
  138. }
  139. device_initcall(meson_mx_socinfo_init);