1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/init.h>
8 #include <linux/of_address.h>
9 #include <linux/slab.h>
10 #include <linux/sys_soc.h>
11 #include <linux/platform_device.h>
16 #define IMX8MQ_SW_INFO_B1 0x40
17 #define IMX8MQ_SW_MAGIC_B1 0xff0055aa
19 struct imx8_soc_data {
21 u32 (*soc_revision)(void);
24 static u32 __init imx8mq_soc_revision(void)
26 struct device_node *np;
27 void __iomem *ocotp_base;
31 np = of_find_compatible_node(NULL, NULL, "fsl,imx8mq-ocotp");
35 ocotp_base = of_iomap(np, 0);
38 magic = readl_relaxed(ocotp_base + IMX8MQ_SW_INFO_B1);
39 if (magic == IMX8MQ_SW_MAGIC_B1)
49 static const struct imx8_soc_data imx8mq_soc_data = {
51 .soc_revision = imx8mq_soc_revision,
54 static const struct of_device_id imx8_soc_match[] = {
55 { .compatible = "fsl,imx8mq", .data = &imx8mq_soc_data, },
59 #define imx8_revision(soc_rev) \
61 kasprintf(GFP_KERNEL, "%d.%d", (soc_rev >> 4) & 0xf, soc_rev & 0xf) : \
64 static int __init imx8_soc_init(void)
66 struct soc_device_attribute *soc_dev_attr;
67 struct soc_device *soc_dev;
68 struct device_node *root;
69 const struct of_device_id *id;
71 const struct imx8_soc_data *data;
74 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
78 soc_dev_attr->family = "Freescale i.MX";
80 root = of_find_node_by_path("/");
81 ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
85 id = of_match_node(imx8_soc_match, root);
93 soc_dev_attr->soc_id = data->name;
94 if (data->soc_revision)
95 soc_rev = data->soc_revision();
98 soc_dev_attr->revision = imx8_revision(soc_rev);
99 if (!soc_dev_attr->revision)
102 soc_dev = soc_device_register(soc_dev_attr);
106 if (IS_ENABLED(CONFIG_ARM_IMX_CPUFREQ_DT))
107 platform_device_register_simple("imx-cpufreq-dt", -1, NULL, 0);
112 kfree(soc_dev_attr->revision);
118 device_initcall(imx8_soc_init);