1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/mfd/syscon.h>
8 #include <linux/of_address.h>
9 #include <linux/regmap.h>
10 #include <linux/slab.h>
11 #include <linux/sys_soc.h>
13 #include <soc/imx/cpu.h>
14 #include <soc/imx/revision.h>
18 #define OCOTP_UID_H 0x420
19 #define OCOTP_UID_L 0x410
21 #define OCOTP_ULP_UID_1 0x4b0
22 #define OCOTP_ULP_UID_2 0x4c0
23 #define OCOTP_ULP_UID_3 0x4d0
24 #define OCOTP_ULP_UID_4 0x4e0
26 static int __init imx_soc_device_init(void)
28 struct soc_device_attribute *soc_dev_attr;
29 const char *ocotp_compat = NULL;
30 struct soc_device *soc_dev;
31 struct device_node *root;
32 struct regmap *ocotp = NULL;
39 /* Return early if this is running on devices with different SoCs */
43 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
47 soc_dev_attr->family = "Freescale i.MX";
49 root = of_find_node_by_path("/");
50 ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
55 switch (__mxc_cpu_type) {
78 ocotp_compat = "fsl,imx51-iim";
82 ocotp_compat = "fsl,imx53-iim";
86 ocotp_compat = "fsl,imx6sl-ocotp";
90 ocotp_compat = "fsl,imx6q-ocotp";
94 ocotp_compat = "fsl,imx6sx-ocotp";
98 ocotp_compat = "fsl,imx6q-ocotp";
102 ocotp_compat = "fsl,imx6ul-ocotp";
105 case MXC_CPU_IMX6ULL:
106 ocotp_compat = "fsl,imx6ull-ocotp";
109 case MXC_CPU_IMX6ULZ:
110 ocotp_compat = "fsl,imx6ull-ocotp";
113 case MXC_CPU_IMX6SLL:
114 ocotp_compat = "fsl,imx6sll-ocotp";
118 ocotp_compat = "fsl,imx7d-ocotp";
121 case MXC_CPU_IMX7ULP:
122 ocotp_compat = "fsl,imx7ulp-ocotp";
126 ocotp_compat = "fsl,vf610-ocotp";
130 ocotp_compat = "fsl,vf610-ocotp";
134 ocotp_compat = "fsl,vf610-ocotp";
138 ocotp_compat = "fsl,vf610-ocotp";
144 soc_dev_attr->soc_id = soc_id;
147 ocotp = syscon_regmap_lookup_by_compatible(ocotp_compat);
149 pr_err("%s: failed to find %s regmap!\n", __func__, ocotp_compat);
152 if (!IS_ERR_OR_NULL(ocotp)) {
153 if (__mxc_cpu_type == MXC_CPU_IMX7ULP) {
154 regmap_read(ocotp, OCOTP_ULP_UID_4, &val);
155 soc_uid = val & 0xffff;
156 regmap_read(ocotp, OCOTP_ULP_UID_3, &val);
158 soc_uid |= val & 0xffff;
159 regmap_read(ocotp, OCOTP_ULP_UID_2, &val);
161 soc_uid |= val & 0xffff;
162 regmap_read(ocotp, OCOTP_ULP_UID_1, &val);
164 soc_uid |= val & 0xffff;
165 } else if (__mxc_cpu_type == MXC_CPU_MX51 ||
166 __mxc_cpu_type == MXC_CPU_MX53) {
167 for (i=0; i < 8; i++) {
168 regmap_read(ocotp, IIM_UID + i*4, &val);
170 soc_uid |= (val & 0xff);
173 regmap_read(ocotp, OCOTP_UID_H, &val);
175 regmap_read(ocotp, OCOTP_UID_L, &val);
181 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d",
182 (imx_get_soc_revision() >> 4) & 0xf,
183 imx_get_soc_revision() & 0xf);
184 if (!soc_dev_attr->revision) {
189 soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX", soc_uid);
190 if (!soc_dev_attr->serial_number) {
195 soc_dev = soc_device_register(soc_dev_attr);
196 if (IS_ERR(soc_dev)) {
197 ret = PTR_ERR(soc_dev);
198 goto free_serial_number;
204 kfree(soc_dev_attr->serial_number);
206 kfree(soc_dev_attr->revision);
211 device_initcall(imx_soc_device_init);