1 // SPDX-License-Identifier: GPL-2.0-only
3 * ID and revision information for mvebu SoCs
5 * Copyright (C) 2014 Marvell
7 * Gregory CLEMENT <gregory.clement@free-electrons.com>
9 * All the mvebu SoCs have information related to their variant and
10 * revision that can be read from the PCI control register. This is
11 * done before the PCI initialization to avoid any conflict. Once the
12 * ID and revision are retrieved, the mapping is freed.
15 #define pr_fmt(fmt) "mvebu-soc-id: " fmt
17 #include <linux/clk.h>
18 #include <linux/init.h>
20 #include <linux/kernel.h>
22 #include <linux/of_address.h>
23 #include <linux/slab.h>
24 #include <linux/sys_soc.h>
26 #include "mvebu-soc-id.h"
28 #define PCIE_DEV_ID_OFF 0x0
29 #define PCIE_DEV_REV_OFF 0x8
31 #define SOC_ID_MASK 0xFFFF0000
32 #define SOC_REV_MASK 0xFF
34 static u32 soc_dev_id;
36 static bool is_id_valid;
38 static const struct of_device_id mvebu_pcie_of_match_table[] = {
39 { .compatible = "marvell,armada-xp-pcie", },
40 { .compatible = "marvell,armada-370-pcie", },
41 { .compatible = "marvell,kirkwood-pcie" },
45 int mvebu_get_soc_id(u32 *dev, u32 *rev)
55 static int __init get_soc_id_by_pci(void)
57 struct device_node *np;
59 void __iomem *pci_base;
61 struct device_node *child;
63 np = of_find_matching_node(NULL, mvebu_pcie_of_match_table);
68 * ID and revision are available from any port, so we
69 * just pick the first one
71 child = of_get_next_child(np, NULL);
73 pr_err("cannot get pci node\n");
78 clk = of_clk_get_by_name(child, NULL);
80 pr_err("cannot get clock\n");
85 ret = clk_prepare_enable(clk);
87 pr_err("cannot enable clock\n");
91 pci_base = of_iomap(child, 0);
92 if (pci_base == NULL) {
93 pr_err("cannot map registers\n");
99 soc_dev_id = readl(pci_base + PCIE_DEV_ID_OFF) >> 16;
102 soc_rev = readl(pci_base + PCIE_DEV_REV_OFF) & SOC_REV_MASK;
106 pr_info("MVEBU SoC ID=0x%X, Rev=0x%X\n", soc_dev_id, soc_rev);
112 * If the PCIe unit is actually enabled and we have PCI
113 * support in the kernel, we intentionally do not release the
114 * reference to the clock. We want to keep it running since
115 * the bootloader does some PCIe link configuration that the
116 * kernel is for now unable to do, and gating the clock would
117 * make us loose this precious configuration.
119 if (!of_device_is_available(child) || !IS_ENABLED(CONFIG_PCI_MVEBU)) {
120 clk_disable_unprepare(clk);
131 static int __init mvebu_soc_id_init(void)
135 * First try to get the ID and the revision by the system
136 * register and use PCI registers only if it is not possible
138 if (!mvebu_system_controller_get_soc_id(&soc_dev_id, &soc_rev)) {
140 pr_info("MVEBU SoC ID=0x%X, Rev=0x%X\n", soc_dev_id, soc_rev);
144 return get_soc_id_by_pci();
146 early_initcall(mvebu_soc_id_init);
148 static int __init mvebu_soc_device(void)
150 struct soc_device_attribute *soc_dev_attr;
151 struct soc_device *soc_dev;
153 /* Also protects against running on non-mvebu systems */
157 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
161 soc_dev_attr->family = kasprintf(GFP_KERNEL, "Marvell");
162 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%X", soc_rev);
163 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%X", soc_dev_id);
165 soc_dev = soc_device_register(soc_dev_attr);
166 if (IS_ERR(soc_dev)) {
167 kfree(soc_dev_attr->family);
168 kfree(soc_dev_attr->revision);
169 kfree(soc_dev_attr->soc_id);
175 postcore_initcall(mvebu_soc_device);