1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 * Copyright (c) 2020 Krzysztof Kozlowski <krzk@kernel.org>
7 * Exynos - CHIP ID support
8 * Author: Pankaj Dubey <pankaj.dubey@samsung.com>
9 * Author: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
10 * Author: Krzysztof Kozlowski <krzk@kernel.org>
12 * Samsung Exynos SoC Adaptive Supply Voltage and Chip ID support
15 #include <linux/device.h>
16 #include <linux/errno.h>
17 #include <linux/mfd/syscon.h>
19 #include <linux/platform_device.h>
20 #include <linux/regmap.h>
21 #include <linux/slab.h>
22 #include <linux/soc/samsung/exynos-chipid.h>
23 #include <linux/sys_soc.h>
25 #include "exynos-asv.h"
27 static const struct exynos_soc_id {
31 /* List ordered by SoC name */
32 { "EXYNOS3250", 0xE3472000 },
33 { "EXYNOS4210", 0x43200000 }, /* EVT0 revision */
34 { "EXYNOS4210", 0x43210000 },
35 { "EXYNOS4212", 0x43220000 },
36 { "EXYNOS4412", 0xE4412000 },
37 { "EXYNOS5250", 0x43520000 },
38 { "EXYNOS5260", 0xE5260000 },
39 { "EXYNOS5410", 0xE5410000 },
40 { "EXYNOS5420", 0xE5420000 },
41 { "EXYNOS5433", 0xE5433000 },
42 { "EXYNOS5440", 0xE5440000 },
43 { "EXYNOS5800", 0xE5422000 },
44 { "EXYNOS7420", 0xE7420000 },
47 static const char *product_id_to_soc_id(unsigned int product_id)
51 for (i = 0; i < ARRAY_SIZE(soc_ids); i++)
52 if ((product_id & EXYNOS_MASK) == soc_ids[i].id)
53 return soc_ids[i].name;
57 static int exynos_chipid_probe(struct platform_device *pdev)
59 struct soc_device_attribute *soc_dev_attr;
60 struct soc_device *soc_dev;
61 struct device_node *root;
62 struct regmap *regmap;
67 regmap = device_node_to_regmap(pdev->dev.of_node);
69 return PTR_ERR(regmap);
71 ret = regmap_read(regmap, EXYNOS_CHIPID_REG_PRO_ID, &product_id);
75 revision = product_id & EXYNOS_REV_MASK;
77 soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr),
82 soc_dev_attr->family = "Samsung Exynos";
84 root = of_find_node_by_path("/");
85 of_property_read_string(root, "model", &soc_dev_attr->machine);
88 soc_dev_attr->revision = devm_kasprintf(&pdev->dev, GFP_KERNEL,
90 soc_dev_attr->soc_id = product_id_to_soc_id(product_id);
91 if (!soc_dev_attr->soc_id) {
92 pr_err("Unknown SoC\n");
96 /* please note that the actual registration will be deferred */
97 soc_dev = soc_device_register(soc_dev_attr);
99 return PTR_ERR(soc_dev);
101 ret = exynos_asv_init(&pdev->dev, regmap);
105 platform_set_drvdata(pdev, soc_dev);
107 dev_info(soc_device_to_device(soc_dev),
108 "Exynos: CPU[%s] PRO_ID[0x%x] REV[0x%x] Detected\n",
109 soc_dev_attr->soc_id, product_id, revision);
114 soc_device_unregister(soc_dev);
119 static int exynos_chipid_remove(struct platform_device *pdev)
121 struct soc_device *soc_dev = platform_get_drvdata(pdev);
123 soc_device_unregister(soc_dev);
128 static const struct of_device_id exynos_chipid_of_device_ids[] = {
129 { .compatible = "samsung,exynos4210-chipid" },
133 static struct platform_driver exynos_chipid_driver = {
135 .name = "exynos-chipid",
136 .of_match_table = exynos_chipid_of_device_ids,
138 .probe = exynos_chipid_probe,
139 .remove = exynos_chipid_remove,
141 builtin_platform_driver(exynos_chipid_driver);