exynos-chipid.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com/
  5. *
  6. * Exynos - CHIP ID support
  7. * Author: Pankaj Dubey <pankaj.dubey@samsung.com>
  8. * Author: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
  9. */
  10. #include <linux/io.h>
  11. #include <linux/mfd/syscon.h>
  12. #include <linux/of.h>
  13. #include <linux/regmap.h>
  14. #include <linux/slab.h>
  15. #include <linux/soc/samsung/exynos-chipid.h>
  16. #include <linux/sys_soc.h>
  17. static const struct exynos_soc_id {
  18. const char *name;
  19. unsigned int id;
  20. } soc_ids[] = {
  21. { "EXYNOS3250", 0xE3472000 },
  22. { "EXYNOS4210", 0x43200000 }, /* EVT0 revision */
  23. { "EXYNOS4210", 0x43210000 },
  24. { "EXYNOS4212", 0x43220000 },
  25. { "EXYNOS4412", 0xE4412000 },
  26. { "EXYNOS5250", 0x43520000 },
  27. { "EXYNOS5260", 0xE5260000 },
  28. { "EXYNOS5410", 0xE5410000 },
  29. { "EXYNOS5420", 0xE5420000 },
  30. { "EXYNOS5440", 0xE5440000 },
  31. { "EXYNOS5800", 0xE5422000 },
  32. { "EXYNOS7420", 0xE7420000 },
  33. { "EXYNOS5433", 0xE5433000 },
  34. };
  35. static const char * __init product_id_to_soc_id(unsigned int product_id)
  36. {
  37. int i;
  38. for (i = 0; i < ARRAY_SIZE(soc_ids); i++)
  39. if ((product_id & EXYNOS_MASK) == soc_ids[i].id)
  40. return soc_ids[i].name;
  41. return NULL;
  42. }
  43. static int __init exynos_chipid_early_init(void)
  44. {
  45. struct soc_device_attribute *soc_dev_attr;
  46. struct soc_device *soc_dev;
  47. struct device_node *root;
  48. struct device_node *syscon;
  49. struct regmap *regmap;
  50. u32 product_id;
  51. u32 revision;
  52. int ret;
  53. syscon = of_find_compatible_node(NULL, NULL,
  54. "samsung,exynos4210-chipid");
  55. if (!syscon)
  56. return -ENODEV;
  57. regmap = device_node_to_regmap(syscon);
  58. of_node_put(syscon);
  59. if (IS_ERR(regmap))
  60. return PTR_ERR(regmap);
  61. ret = regmap_read(regmap, EXYNOS_CHIPID_REG_PRO_ID, &product_id);
  62. if (ret < 0)
  63. return ret;
  64. revision = product_id & EXYNOS_REV_MASK;
  65. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  66. if (!soc_dev_attr)
  67. return -ENOMEM;
  68. soc_dev_attr->family = "Samsung Exynos";
  69. root = of_find_node_by_path("/");
  70. of_property_read_string(root, "model", &soc_dev_attr->machine);
  71. of_node_put(root);
  72. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%x", revision);
  73. soc_dev_attr->soc_id = product_id_to_soc_id(product_id);
  74. if (!soc_dev_attr->soc_id) {
  75. pr_err("Unknown SoC\n");
  76. ret = -ENODEV;
  77. goto err;
  78. }
  79. /* please note that the actual registration will be deferred */
  80. soc_dev = soc_device_register(soc_dev_attr);
  81. if (IS_ERR(soc_dev)) {
  82. ret = PTR_ERR(soc_dev);
  83. goto err;
  84. }
  85. /* it is too early to use dev_info() here (soc_dev is NULL) */
  86. pr_info("soc soc0: Exynos: CPU[%s] PRO_ID[0x%x] REV[0x%x] Detected\n",
  87. soc_dev_attr->soc_id, product_id, revision);
  88. return 0;
  89. err:
  90. kfree(soc_dev_attr->revision);
  91. kfree(soc_dev_attr);
  92. return ret;
  93. }
  94. early_initcall(exynos_chipid_early_init);