Merge tag 'armsoc-drivers' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-2.6-microblaze.git] / drivers / soc / imx / soc-imx8.c
index b1bd8e2..f924ae8 100644 (file)
@@ -16,6 +16,9 @@
 #define IMX8MQ_SW_INFO_B1              0x40
 #define IMX8MQ_SW_MAGIC_B1             0xff0055aa
 
+/* Same as ANADIG_DIGPROG_IMX7D */
+#define ANADIG_DIGPROG_IMX8MM  0x800
+
 struct imx8_soc_data {
        char *name;
        u32 (*soc_revision)(void);
@@ -46,13 +49,45 @@ out:
        return rev;
 }
 
+static u32 __init imx8mm_soc_revision(void)
+{
+       struct device_node *np;
+       void __iomem *anatop_base;
+       u32 rev;
+
+       np = of_find_compatible_node(NULL, NULL, "fsl,imx8mm-anatop");
+       if (!np)
+               return 0;
+
+       anatop_base = of_iomap(np, 0);
+       WARN_ON(!anatop_base);
+
+       rev = readl_relaxed(anatop_base + ANADIG_DIGPROG_IMX8MM);
+
+       iounmap(anatop_base);
+       of_node_put(np);
+       return rev;
+}
+
 static const struct imx8_soc_data imx8mq_soc_data = {
        .name = "i.MX8MQ",
        .soc_revision = imx8mq_soc_revision,
 };
 
+static const struct imx8_soc_data imx8mm_soc_data = {
+       .name = "i.MX8MM",
+       .soc_revision = imx8mm_soc_revision,
+};
+
+static const struct imx8_soc_data imx8mn_soc_data = {
+       .name = "i.MX8MN",
+       .soc_revision = imx8mm_soc_revision,
+};
+
 static const struct of_device_id imx8_soc_match[] = {
        { .compatible = "fsl,imx8mq", .data = &imx8mq_soc_data, },
+       { .compatible = "fsl,imx8mm", .data = &imx8mm_soc_data, },
+       { .compatible = "fsl,imx8mn", .data = &imx8mn_soc_data, },
        { }
 };
 
@@ -65,7 +100,6 @@ static int __init imx8_soc_init(void)
 {
        struct soc_device_attribute *soc_dev_attr;
        struct soc_device *soc_dev;
-       struct device_node *root;
        const struct of_device_id *id;
        u32 soc_rev = 0;
        const struct imx8_soc_data *data;
@@ -73,20 +107,19 @@ static int __init imx8_soc_init(void)
 
        soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
        if (!soc_dev_attr)
-               return -ENODEV;
+               return -ENOMEM;
 
        soc_dev_attr->family = "Freescale i.MX";
 
-       root = of_find_node_by_path("/");
-       ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
+       ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);
        if (ret)
                goto free_soc;
 
-       id = of_match_node(imx8_soc_match, root);
-       if (!id)
+       id = of_match_node(imx8_soc_match, of_root);
+       if (!id) {
+               ret = -ENODEV;
                goto free_soc;
-
-       of_node_put(root);
+       }
 
        data = id->data;
        if (data) {
@@ -96,12 +129,16 @@ static int __init imx8_soc_init(void)
        }
 
        soc_dev_attr->revision = imx8_revision(soc_rev);
-       if (!soc_dev_attr->revision)
+       if (!soc_dev_attr->revision) {
+               ret = -ENOMEM;
                goto free_soc;
+       }
 
        soc_dev = soc_device_register(soc_dev_attr);
-       if (IS_ERR(soc_dev))
+       if (IS_ERR(soc_dev)) {
+               ret = PTR_ERR(soc_dev);
                goto free_rev;
+       }
 
        if (IS_ENABLED(CONFIG_ARM_IMX_CPUFREQ_DT))
                platform_device_register_simple("imx-cpufreq-dt", -1, NULL, 0);
@@ -109,10 +146,10 @@ static int __init imx8_soc_init(void)
        return 0;
 
 free_rev:
-       kfree(soc_dev_attr->revision);
+       if (strcmp(soc_dev_attr->revision, "unknown"))
+               kfree(soc_dev_attr->revision);
 free_soc:
        kfree(soc_dev_attr);
-       of_node_put(root);
-       return -ENODEV;
+       return ret;
 }
 device_initcall(imx8_soc_init);