1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/mfd/syscon.h>
4 #include <linux/module.h>
7 #include <linux/of_address.h>
8 #include <linux/regmap.h>
9 #include <linux/slab.h>
10 #include <linux/sys_soc.h>
15 #define OCOTP_UID_H 0x420
16 #define OCOTP_UID_L 0x410
18 unsigned int __mxc_cpu_type;
19 static unsigned int imx_soc_revision;
21 void mxc_set_cpu_type(unsigned int type)
23 __mxc_cpu_type = type;
26 void imx_set_soc_revision(unsigned int rev)
28 imx_soc_revision = rev;
31 unsigned int imx_get_soc_revision(void)
33 return imx_soc_revision;
36 void imx_print_silicon_rev(const char *cpu, int srev)
38 if (srev == IMX_CHIP_REVISION_UNKNOWN)
39 pr_info("CPU identified as %s, unknown revision\n", cpu);
41 pr_info("CPU identified as %s, silicon rev %d.%d\n",
42 cpu, (srev >> 4) & 0xf, srev & 0xf);
45 void __init imx_set_aips(void __iomem *base)
49 * Set all MPROTx to be non-bufferable, trusted for R/W,
50 * not forced to user-mode.
52 imx_writel(0x77777777, base + 0x0);
53 imx_writel(0x77777777, base + 0x4);
56 * Set all OPACRx to be non-bufferable, to not require
57 * supervisor privilege level for access, allow for
58 * write access and untrusted master access.
60 imx_writel(0x0, base + 0x40);
61 imx_writel(0x0, base + 0x44);
62 imx_writel(0x0, base + 0x48);
63 imx_writel(0x0, base + 0x4C);
64 reg = imx_readl(base + 0x50) & 0x00FFFFFF;
65 imx_writel(reg, base + 0x50);
68 void __init imx_aips_allow_unprivileged_access(
71 void __iomem *aips_base_addr;
72 struct device_node *np;
74 for_each_compatible_node(np, NULL, compat) {
75 aips_base_addr = of_iomap(np, 0);
76 WARN_ON(!aips_base_addr);
77 imx_set_aips(aips_base_addr);
81 struct device * __init imx_soc_device_init(void)
83 struct soc_device_attribute *soc_dev_attr;
84 const char *ocotp_compat = NULL;
85 struct soc_device *soc_dev;
86 struct device_node *root;
87 struct regmap *ocotp = NULL;
93 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
97 soc_dev_attr->family = "Freescale i.MX";
99 root = of_find_node_by_path("/");
100 ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
105 switch (__mxc_cpu_type) {
131 ocotp_compat = "fsl,imx6sl-ocotp";
135 ocotp_compat = "fsl,imx6q-ocotp";
139 ocotp_compat = "fsl,imx6sx-ocotp";
143 ocotp_compat = "fsl,imx6q-ocotp";
147 ocotp_compat = "fsl,imx6ul-ocotp";
150 case MXC_CPU_IMX6ULL:
151 ocotp_compat = "fsl,imx6ull-ocotp";
154 case MXC_CPU_IMX6ULZ:
155 ocotp_compat = "fsl,imx6ull-ocotp";
158 case MXC_CPU_IMX6SLL:
159 ocotp_compat = "fsl,imx6sll-ocotp";
163 ocotp_compat = "fsl,imx7d-ocotp";
166 case MXC_CPU_IMX7ULP:
172 soc_dev_attr->soc_id = soc_id;
175 ocotp = syscon_regmap_lookup_by_compatible(ocotp_compat);
177 pr_err("%s: failed to find %s regmap!\n", __func__, ocotp_compat);
180 if (!IS_ERR_OR_NULL(ocotp)) {
181 regmap_read(ocotp, OCOTP_UID_H, &val);
183 regmap_read(ocotp, OCOTP_UID_L, &val);
188 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d",
189 (imx_soc_revision >> 4) & 0xf,
190 imx_soc_revision & 0xf);
191 if (!soc_dev_attr->revision)
194 soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX", soc_uid);
195 if (!soc_dev_attr->serial_number)
198 soc_dev = soc_device_register(soc_dev_attr);
200 goto free_serial_number;
202 return soc_device_to_device(soc_dev);
205 kfree(soc_dev_attr->serial_number);
207 kfree(soc_dev_attr->revision);