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>
16 #define OCOTP_UID_H 0x420
17 #define OCOTP_UID_L 0x410
19 #define OCOTP_ULP_UID_1 0x4b0
20 #define OCOTP_ULP_UID_2 0x4c0
21 #define OCOTP_ULP_UID_3 0x4d0
22 #define OCOTP_ULP_UID_4 0x4e0
24 static int __init imx_soc_device_init(void)
26 struct soc_device_attribute *soc_dev_attr;
27 const char *ocotp_compat = NULL;
28 struct soc_device *soc_dev;
29 struct device_node *root;
30 struct regmap *ocotp = NULL;
36 /* Return early if this is running on devices with different SoCs */
40 if (of_machine_is_compatible("fsl,ls1021a"))
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) {
81 ocotp_compat = "fsl,imx6sl-ocotp";
85 ocotp_compat = "fsl,imx6q-ocotp";
89 ocotp_compat = "fsl,imx6sx-ocotp";
93 ocotp_compat = "fsl,imx6q-ocotp";
97 ocotp_compat = "fsl,imx6ul-ocotp";
100 case MXC_CPU_IMX6ULL:
101 ocotp_compat = "fsl,imx6ull-ocotp";
104 case MXC_CPU_IMX6ULZ:
105 ocotp_compat = "fsl,imx6ull-ocotp";
108 case MXC_CPU_IMX6SLL:
109 ocotp_compat = "fsl,imx6sll-ocotp";
113 ocotp_compat = "fsl,imx7d-ocotp";
116 case MXC_CPU_IMX7ULP:
117 ocotp_compat = "fsl,imx7ulp-ocotp";
121 ocotp_compat = "fsl,vf610-ocotp";
125 ocotp_compat = "fsl,vf610-ocotp";
129 ocotp_compat = "fsl,vf610-ocotp";
133 ocotp_compat = "fsl,vf610-ocotp";
139 soc_dev_attr->soc_id = soc_id;
142 ocotp = syscon_regmap_lookup_by_compatible(ocotp_compat);
144 pr_err("%s: failed to find %s regmap!\n", __func__, ocotp_compat);
147 if (!IS_ERR_OR_NULL(ocotp)) {
148 if (__mxc_cpu_type == MXC_CPU_IMX7ULP) {
149 regmap_read(ocotp, OCOTP_ULP_UID_4, &val);
150 soc_uid = val & 0xffff;
151 regmap_read(ocotp, OCOTP_ULP_UID_3, &val);
153 soc_uid |= val & 0xffff;
154 regmap_read(ocotp, OCOTP_ULP_UID_2, &val);
156 soc_uid |= val & 0xffff;
157 regmap_read(ocotp, OCOTP_ULP_UID_1, &val);
159 soc_uid |= val & 0xffff;
161 regmap_read(ocotp, OCOTP_UID_H, &val);
163 regmap_read(ocotp, OCOTP_UID_L, &val);
169 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d",
170 (imx_get_soc_revision() >> 4) & 0xf,
171 imx_get_soc_revision() & 0xf);
172 if (!soc_dev_attr->revision) {
177 soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX", soc_uid);
178 if (!soc_dev_attr->serial_number) {
183 soc_dev = soc_device_register(soc_dev_attr);
184 if (IS_ERR(soc_dev)) {
185 ret = PTR_ERR(soc_dev);
186 goto free_serial_number;
192 kfree(soc_dev_attr->serial_number);
194 kfree(soc_dev_attr->revision);
199 device_initcall(imx_soc_device_init);