2 * ID and revision information for mvebu SoCs
4 * Copyright (C) 2014 Marvell
6 * Gregory CLEMENT <gregory.clement@free-electrons.com>
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
12 * All the mvebu SoCs have information related to their variant and
13 * revision that can be read from the PCI control register. This is
14 * done before the PCI initialization to avoid any conflict. Once the
15 * ID and revision are retrieved, the mapping is freed.
18 #define pr_fmt(fmt) "mvebu-soc-id: " fmt
20 #include <linux/clk.h>
21 #include <linux/init.h>
23 #include <linux/kernel.h>
25 #include <linux/of_address.h>
26 #include <linux/slab.h>
27 #include <linux/sys_soc.h>
29 #include "mvebu-soc-id.h"
31 #define PCIE_DEV_ID_OFF 0x0
32 #define PCIE_DEV_REV_OFF 0x8
34 #define SOC_ID_MASK 0xFFFF0000
35 #define SOC_REV_MASK 0xFF
37 static u32 soc_dev_id
;
39 static bool is_id_valid
;
41 static const struct of_device_id mvebu_pcie_of_match_table
[] = {
42 { .compatible
= "marvell,armada-xp-pcie", },
43 { .compatible
= "marvell,armada-370-pcie", },
44 { .compatible
= "marvell,kirkwood-pcie" },
48 int mvebu_get_soc_id(u32
*dev
, u32
*rev
)
58 static int __init
get_soc_id_by_pci(void)
60 struct device_node
*np
;
62 void __iomem
*pci_base
;
64 struct device_node
*child
;
66 np
= of_find_matching_node(NULL
, mvebu_pcie_of_match_table
);
71 * ID and revision are available from any port, so we
72 * just pick the first one
74 child
= of_get_next_child(np
, NULL
);
76 pr_err("cannot get pci node\n");
81 clk
= of_clk_get_by_name(child
, NULL
);
83 pr_err("cannot get clock\n");
88 ret
= clk_prepare_enable(clk
);
90 pr_err("cannot enable clock\n");
94 pci_base
= of_iomap(child
, 0);
95 if (pci_base
== NULL
) {
96 pr_err("cannot map registers\n");
102 soc_dev_id
= readl(pci_base
+ PCIE_DEV_ID_OFF
) >> 16;
105 soc_rev
= readl(pci_base
+ PCIE_DEV_REV_OFF
) & SOC_REV_MASK
;
109 pr_info("MVEBU SoC ID=0x%X, Rev=0x%X\n", soc_dev_id
, soc_rev
);
115 * If the PCIe unit is actually enabled and we have PCI
116 * support in the kernel, we intentionally do not release the
117 * reference to the clock. We want to keep it running since
118 * the bootloader does some PCIe link configuration that the
119 * kernel is for now unable to do, and gating the clock would
120 * make us loose this precious configuration.
122 if (!of_device_is_available(child
) || !IS_ENABLED(CONFIG_PCI_MVEBU
)) {
123 clk_disable_unprepare(clk
);
134 static int __init
mvebu_soc_id_init(void)
138 * First try to get the ID and the revision by the system
139 * register and use PCI registers only if it is not possible
141 if (!mvebu_system_controller_get_soc_id(&soc_dev_id
, &soc_rev
)) {
143 pr_info("MVEBU SoC ID=0x%X, Rev=0x%X\n", soc_dev_id
, soc_rev
);
147 return get_soc_id_by_pci();
149 early_initcall(mvebu_soc_id_init
);
151 static int __init
mvebu_soc_device(void)
153 struct soc_device_attribute
*soc_dev_attr
;
154 struct soc_device
*soc_dev
;
156 /* Also protects against running on non-mvebu systems */
160 soc_dev_attr
= kzalloc(sizeof(*soc_dev_attr
), GFP_KERNEL
);
164 soc_dev_attr
->family
= kasprintf(GFP_KERNEL
, "Marvell");
165 soc_dev_attr
->revision
= kasprintf(GFP_KERNEL
, "%X", soc_rev
);
166 soc_dev_attr
->soc_id
= kasprintf(GFP_KERNEL
, "%X", soc_dev_id
);
168 soc_dev
= soc_device_register(soc_dev_attr
);
169 if (IS_ERR(soc_dev
)) {
170 kfree(soc_dev_attr
->family
);
171 kfree(soc_dev_attr
->revision
);
172 kfree(soc_dev_attr
->soc_id
);
178 postcore_initcall(mvebu_soc_device
);