exynos-chipid.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. 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 regmap *regmap;
  49. u32 product_id;
  50. u32 revision;
  51. int ret;
  52. regmap = syscon_regmap_lookup_by_compatible("samsung,exynos4210-chipid");
  53. if (IS_ERR(regmap))
  54. return PTR_ERR(regmap);
  55. ret = regmap_read(regmap, EXYNOS_CHIPID_REG_PRO_ID, &product_id);
  56. if (ret < 0)
  57. return ret;
  58. revision = product_id & EXYNOS_REV_MASK;
  59. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  60. if (!soc_dev_attr)
  61. return -ENOMEM;
  62. soc_dev_attr->family = "Samsung Exynos";
  63. root = of_find_node_by_path("/");
  64. of_property_read_string(root, "model", &soc_dev_attr->machine);
  65. of_node_put(root);
  66. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%x", revision);
  67. soc_dev_attr->soc_id = product_id_to_soc_id(product_id);
  68. if (!soc_dev_attr->soc_id) {
  69. pr_err("Unknown SoC\n");
  70. ret = -ENODEV;
  71. goto err;
  72. }
  73. /* please note that the actual registration will be deferred */
  74. soc_dev = soc_device_register(soc_dev_attr);
  75. if (IS_ERR(soc_dev)) {
  76. ret = PTR_ERR(soc_dev);
  77. goto err;
  78. }
  79. /* it is too early to use dev_info() here (soc_dev is NULL) */
  80. pr_info("soc soc0: Exynos: CPU[%s] PRO_ID[0x%x] REV[0x%x] Detected\n",
  81. soc_dev_attr->soc_id, product_id, revision);
  82. return 0;
  83. err:
  84. kfree(soc_dev_attr->revision);
  85. kfree(soc_dev_attr);
  86. return ret;
  87. }
  88. early_initcall(exynos_chipid_early_init);