1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
6 * EXYNOS - CHIP ID support
7 * Author: Pankaj Dubey <pankaj.dubey@samsung.com>
8 * Author: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
13 #include <linux/of_address.h>
14 #include <linux/of_platform.h>
15 #include <linux/platform_device.h>
16 #include <linux/slab.h>
17 #include <linux/sys_soc.h>
19 #include "exynos-chipid.h"
21 static const struct exynos_soc_id {
25 { "EXYNOS3250", 0xE3472000 },
26 { "EXYNOS4210", 0x43200000 }, /* EVT0 revision */
27 { "EXYNOS4210", 0x43210000 },
28 { "EXYNOS4212", 0x43220000 },
29 { "EXYNOS4412", 0xE4412000 },
30 { "EXYNOS5250", 0x43520000 },
31 { "EXYNOS5260", 0xE5260000 },
32 { "EXYNOS5410", 0xE5410000 },
33 { "EXYNOS5420", 0xE5420000 },
34 { "EXYNOS5440", 0xE5440000 },
35 { "EXYNOS5800", 0xE5422000 },
36 { "EXYNOS7420", 0xE7420000 },
37 { "EXYNOS5433", 0xE5433000 },
40 static void __iomem *exynos_abb_base;
41 static void __iomem *exynos_chipid_base;
43 unsigned int exynos_chipid_read(unsigned int offset)
45 return readl_relaxed(exynos_chipid_base + offset);
48 unsigned int exynos_chipid_read_bits(unsigned int offset, unsigned int shift,
51 return (readl_relaxed(exynos_chipid_base + offset) >> shift) & mask;
54 unsigned int exynos_chipid_abb_read(unsigned int offset)
56 if (WARN_ON(exynos_abb_base == NULL))
59 return readl_relaxed(exynos_abb_base + offset);
62 static const char * __init product_id_to_soc_id(unsigned int product_id)
66 for (i = 0; i < ARRAY_SIZE(soc_ids); i++)
67 if ((product_id & EXYNOS_MASK) == soc_ids[i].id)
68 return soc_ids[i].name;
72 int __init exynos_chipid_early_init(void)
74 struct soc_device_attribute *soc_dev_attr;
75 struct soc_device *soc_dev;
76 struct device_node *root;
77 struct device_node *np;
81 /* look up for chipid node */
82 np = of_find_compatible_node(NULL, NULL, "samsung,exynos4210-chipid");
86 exynos_chipid_base = of_iomap(np, 0);
87 if (!exynos_chipid_base) {
89 pr_err("Failed to map SoC CHIPID\n");
93 if (of_device_is_compatible(np, "samsung,exynos5433-chipid")) {
94 exynos_abb_base = of_iomap(np, 1);
95 if (!exynos_abb_base) {
97 pr_err("Failed to map SoC CHIPID/ABB\n");
103 product_id = exynos_chipid_read(EXYNOS_CHIPID_REG_PRO_ID);
104 revision = product_id & EXYNOS_REV_MASK;
106 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
110 soc_dev_attr->family = "Samsung Exynos";
112 root = of_find_node_by_path("/");
113 of_property_read_string(root, "model", &soc_dev_attr->machine);
116 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%x", revision);
117 soc_dev_attr->soc_id = product_id_to_soc_id(product_id);
118 if (!soc_dev_attr->soc_id) {
119 pr_err("Unknown SoC\n");
123 /* please note that the actual registration will be deferred */
124 soc_dev = soc_device_register(soc_dev_attr);
125 if (IS_ERR(soc_dev)) {
126 kfree(soc_dev_attr->revision);
128 return PTR_ERR(soc_dev);
131 /* it is too early to use dev_info() here (soc_dev is NULL) */
132 pr_info("soc soc0: Exynos: CPU[%s] PRO_ID[0x%x] REV[0x%x] Detected\n",
133 soc_dev_attr->soc_id, product_id, revision);
137 early_initcall(exynos_chipid_early_init);