exynos-chipid.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com/
  5. * Copyright (c) 2020 Krzysztof Kozlowski <[email protected]>
  6. *
  7. * Exynos - CHIP ID support
  8. * Author: Pankaj Dubey <[email protected]>
  9. * Author: Bartlomiej Zolnierkiewicz <[email protected]>
  10. * Author: Krzysztof Kozlowski <[email protected]>
  11. *
  12. * Samsung Exynos SoC Adaptive Supply Voltage and Chip ID support
  13. */
  14. #include <linux/device.h>
  15. #include <linux/errno.h>
  16. #include <linux/mfd/syscon.h>
  17. #include <linux/module.h>
  18. #include <linux/of.h>
  19. #include <linux/of_device.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/regmap.h>
  22. #include <linux/slab.h>
  23. #include <linux/soc/samsung/exynos-chipid.h>
  24. #include <linux/sys_soc.h>
  25. #include "exynos-asv.h"
  26. struct exynos_chipid_variant {
  27. unsigned int rev_reg; /* revision register offset */
  28. unsigned int main_rev_shift; /* main revision offset in rev_reg */
  29. unsigned int sub_rev_shift; /* sub revision offset in rev_reg */
  30. };
  31. struct exynos_chipid_info {
  32. u32 product_id;
  33. u32 revision;
  34. };
  35. static const struct exynos_soc_id {
  36. const char *name;
  37. unsigned int id;
  38. } soc_ids[] = {
  39. /* List ordered by SoC name */
  40. /* Compatible with: samsung,exynos4210-chipid */
  41. { "EXYNOS3250", 0xE3472000 },
  42. { "EXYNOS4210", 0x43200000 }, /* EVT0 revision */
  43. { "EXYNOS4210", 0x43210000 },
  44. { "EXYNOS4212", 0x43220000 },
  45. { "EXYNOS4412", 0xE4412000 },
  46. { "EXYNOS5250", 0x43520000 },
  47. { "EXYNOS5260", 0xE5260000 },
  48. { "EXYNOS5410", 0xE5410000 },
  49. { "EXYNOS5420", 0xE5420000 },
  50. { "EXYNOS5433", 0xE5433000 },
  51. { "EXYNOS5440", 0xE5440000 },
  52. { "EXYNOS5800", 0xE5422000 },
  53. { "EXYNOS7420", 0xE7420000 },
  54. /* Compatible with: samsung,exynos850-chipid */
  55. { "EXYNOS7885", 0xE7885000 },
  56. { "EXYNOS850", 0xE3830000 },
  57. { "EXYNOSAUTOV9", 0xAAA80000 },
  58. };
  59. static const char *product_id_to_soc_id(unsigned int product_id)
  60. {
  61. int i;
  62. for (i = 0; i < ARRAY_SIZE(soc_ids); i++)
  63. if (product_id == soc_ids[i].id)
  64. return soc_ids[i].name;
  65. return NULL;
  66. }
  67. static int exynos_chipid_get_chipid_info(struct regmap *regmap,
  68. const struct exynos_chipid_variant *data,
  69. struct exynos_chipid_info *soc_info)
  70. {
  71. int ret;
  72. unsigned int val, main_rev, sub_rev;
  73. ret = regmap_read(regmap, EXYNOS_CHIPID_REG_PRO_ID, &val);
  74. if (ret < 0)
  75. return ret;
  76. soc_info->product_id = val & EXYNOS_MASK;
  77. if (data->rev_reg != EXYNOS_CHIPID_REG_PRO_ID) {
  78. ret = regmap_read(regmap, data->rev_reg, &val);
  79. if (ret < 0)
  80. return ret;
  81. }
  82. main_rev = (val >> data->main_rev_shift) & EXYNOS_REV_PART_MASK;
  83. sub_rev = (val >> data->sub_rev_shift) & EXYNOS_REV_PART_MASK;
  84. soc_info->revision = (main_rev << EXYNOS_REV_PART_SHIFT) | sub_rev;
  85. return 0;
  86. }
  87. static int exynos_chipid_probe(struct platform_device *pdev)
  88. {
  89. const struct exynos_chipid_variant *drv_data;
  90. struct exynos_chipid_info soc_info;
  91. struct soc_device_attribute *soc_dev_attr;
  92. struct soc_device *soc_dev;
  93. struct device_node *root;
  94. struct regmap *regmap;
  95. int ret;
  96. drv_data = of_device_get_match_data(&pdev->dev);
  97. if (!drv_data)
  98. return -EINVAL;
  99. regmap = device_node_to_regmap(pdev->dev.of_node);
  100. if (IS_ERR(regmap))
  101. return PTR_ERR(regmap);
  102. ret = exynos_chipid_get_chipid_info(regmap, drv_data, &soc_info);
  103. if (ret < 0)
  104. return ret;
  105. soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr),
  106. GFP_KERNEL);
  107. if (!soc_dev_attr)
  108. return -ENOMEM;
  109. soc_dev_attr->family = "Samsung Exynos";
  110. root = of_find_node_by_path("/");
  111. of_property_read_string(root, "model", &soc_dev_attr->machine);
  112. of_node_put(root);
  113. soc_dev_attr->revision = devm_kasprintf(&pdev->dev, GFP_KERNEL,
  114. "%x", soc_info.revision);
  115. soc_dev_attr->soc_id = product_id_to_soc_id(soc_info.product_id);
  116. if (!soc_dev_attr->soc_id) {
  117. pr_err("Unknown SoC\n");
  118. return -ENODEV;
  119. }
  120. /* please note that the actual registration will be deferred */
  121. soc_dev = soc_device_register(soc_dev_attr);
  122. if (IS_ERR(soc_dev))
  123. return PTR_ERR(soc_dev);
  124. ret = exynos_asv_init(&pdev->dev, regmap);
  125. if (ret)
  126. goto err;
  127. platform_set_drvdata(pdev, soc_dev);
  128. dev_info(&pdev->dev, "Exynos: CPU[%s] PRO_ID[0x%x] REV[0x%x] Detected\n",
  129. soc_dev_attr->soc_id, soc_info.product_id, soc_info.revision);
  130. return 0;
  131. err:
  132. soc_device_unregister(soc_dev);
  133. return ret;
  134. }
  135. static int exynos_chipid_remove(struct platform_device *pdev)
  136. {
  137. struct soc_device *soc_dev = platform_get_drvdata(pdev);
  138. soc_device_unregister(soc_dev);
  139. return 0;
  140. }
  141. static const struct exynos_chipid_variant exynos4210_chipid_drv_data = {
  142. .rev_reg = 0x0,
  143. .main_rev_shift = 4,
  144. .sub_rev_shift = 0,
  145. };
  146. static const struct exynos_chipid_variant exynos850_chipid_drv_data = {
  147. .rev_reg = 0x10,
  148. .main_rev_shift = 20,
  149. .sub_rev_shift = 16,
  150. };
  151. static const struct of_device_id exynos_chipid_of_device_ids[] = {
  152. {
  153. .compatible = "samsung,exynos4210-chipid",
  154. .data = &exynos4210_chipid_drv_data,
  155. }, {
  156. .compatible = "samsung,exynos850-chipid",
  157. .data = &exynos850_chipid_drv_data,
  158. },
  159. { }
  160. };
  161. MODULE_DEVICE_TABLE(of, exynos_chipid_of_device_ids);
  162. static struct platform_driver exynos_chipid_driver = {
  163. .driver = {
  164. .name = "exynos-chipid",
  165. .of_match_table = exynos_chipid_of_device_ids,
  166. },
  167. .probe = exynos_chipid_probe,
  168. .remove = exynos_chipid_remove,
  169. };
  170. module_platform_driver(exynos_chipid_driver);
  171. MODULE_DESCRIPTION("Samsung Exynos ChipID controller and ASV driver");
  172. MODULE_AUTHOR("Bartlomiej Zolnierkiewicz <[email protected]>");
  173. MODULE_AUTHOR("Krzysztof Kozlowski <[email protected]>");
  174. MODULE_AUTHOR("Pankaj Dubey <[email protected]>");
  175. MODULE_AUTHOR("Sylwester Nawrocki <[email protected]>");
  176. MODULE_LICENSE("GPL");