1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2019 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>
12 #include <linux/mfd/syscon.h>
14 #include <linux/regmap.h>
15 #include <linux/slab.h>
16 #include <linux/soc/samsung/exynos-chipid.h>
17 #include <linux/sys_soc.h>
19 static const struct exynos_soc_id
{
23 { "EXYNOS3250", 0xE3472000 },
24 { "EXYNOS4210", 0x43200000 }, /* EVT0 revision */
25 { "EXYNOS4210", 0x43210000 },
26 { "EXYNOS4212", 0x43220000 },
27 { "EXYNOS4412", 0xE4412000 },
28 { "EXYNOS5250", 0x43520000 },
29 { "EXYNOS5260", 0xE5260000 },
30 { "EXYNOS5410", 0xE5410000 },
31 { "EXYNOS5420", 0xE5420000 },
32 { "EXYNOS5440", 0xE5440000 },
33 { "EXYNOS5800", 0xE5422000 },
34 { "EXYNOS7420", 0xE7420000 },
35 { "EXYNOS5433", 0xE5433000 },
38 static const char * __init
product_id_to_soc_id(unsigned int product_id
)
42 for (i
= 0; i
< ARRAY_SIZE(soc_ids
); i
++)
43 if ((product_id
& EXYNOS_MASK
) == soc_ids
[i
].id
)
44 return soc_ids
[i
].name
;
48 static int __init
exynos_chipid_early_init(void)
50 struct soc_device_attribute
*soc_dev_attr
;
51 struct soc_device
*soc_dev
;
52 struct device_node
*root
;
53 struct device_node
*syscon
;
54 struct regmap
*regmap
;
59 syscon
= of_find_compatible_node(NULL
, NULL
,
60 "samsung,exynos4210-chipid");
64 regmap
= device_node_to_regmap(syscon
);
68 return PTR_ERR(regmap
);
70 ret
= regmap_read(regmap
, EXYNOS_CHIPID_REG_PRO_ID
, &product_id
);
74 revision
= product_id
& EXYNOS_REV_MASK
;
76 soc_dev_attr
= kzalloc(sizeof(*soc_dev_attr
), GFP_KERNEL
);
80 soc_dev_attr
->family
= "Samsung Exynos";
82 root
= of_find_node_by_path("/");
83 of_property_read_string(root
, "model", &soc_dev_attr
->machine
);
86 soc_dev_attr
->revision
= kasprintf(GFP_KERNEL
, "%x", revision
);
87 soc_dev_attr
->soc_id
= product_id_to_soc_id(product_id
);
88 if (!soc_dev_attr
->soc_id
) {
89 pr_err("Unknown SoC\n");
94 /* please note that the actual registration will be deferred */
95 soc_dev
= soc_device_register(soc_dev_attr
);
96 if (IS_ERR(soc_dev
)) {
97 ret
= PTR_ERR(soc_dev
);
101 /* it is too early to use dev_info() here (soc_dev is NULL) */
102 pr_info("soc soc0: Exynos: CPU[%s] PRO_ID[0x%x] REV[0x%x] Detected\n",
103 soc_dev_attr
->soc_id
, product_id
, revision
);
108 kfree(soc_dev_attr
->revision
);
113 early_initcall(exynos_chipid_early_init
);