1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright © 2014 NVIDIA Corporation
4 * Copyright © 2015 Broadcom Corporation
9 #include <linux/of_address.h>
10 #include <linux/slab.h>
11 #include <linux/soc/brcmstb/brcmstb.h>
12 #include <linux/sys_soc.h>
15 static u32 product_id;
17 u32 brcmstb_get_family_id(void)
21 EXPORT_SYMBOL(brcmstb_get_family_id);
23 u32 brcmstb_get_product_id(void)
27 EXPORT_SYMBOL(brcmstb_get_product_id);
29 static const struct of_device_id sun_top_ctrl_match[] = {
30 { .compatible = "brcm,bcm7125-sun-top-ctrl", },
31 { .compatible = "brcm,bcm7346-sun-top-ctrl", },
32 { .compatible = "brcm,bcm7358-sun-top-ctrl", },
33 { .compatible = "brcm,bcm7360-sun-top-ctrl", },
34 { .compatible = "brcm,bcm7362-sun-top-ctrl", },
35 { .compatible = "brcm,bcm7420-sun-top-ctrl", },
36 { .compatible = "brcm,bcm7425-sun-top-ctrl", },
37 { .compatible = "brcm,bcm7429-sun-top-ctrl", },
38 { .compatible = "brcm,bcm7435-sun-top-ctrl", },
39 { .compatible = "brcm,brcmstb-sun-top-ctrl", },
43 static int __init brcmstb_soc_device_early_init(void)
45 struct device_node *sun_top_ctrl;
46 void __iomem *sun_top_ctrl_base;
49 /* We could be on a multi-platform kernel, don't make this fatal but
52 sun_top_ctrl = of_find_matching_node(NULL, sun_top_ctrl_match);
56 sun_top_ctrl_base = of_iomap(sun_top_ctrl, 0);
57 if (!sun_top_ctrl_base) {
62 family_id = readl(sun_top_ctrl_base);
63 product_id = readl(sun_top_ctrl_base + 0x4);
64 iounmap(sun_top_ctrl_base);
66 of_node_put(sun_top_ctrl);
69 early_initcall(brcmstb_soc_device_early_init);
71 static int __init brcmstb_soc_device_init(void)
73 struct soc_device_attribute *soc_dev_attr;
74 struct device_node *sun_top_ctrl;
75 struct soc_device *soc_dev;
78 /* We could be on a multi-platform kernel, don't make this fatal but
81 sun_top_ctrl = of_find_matching_node(NULL, sun_top_ctrl_match);
85 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
91 soc_dev_attr->family = kasprintf(GFP_KERNEL, "%x",
93 family_id >> 16 : family_id >> 8);
94 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%x",
96 product_id >> 16 : product_id >> 8);
97 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%c%d",
98 ((product_id & 0xf0) >> 4) + 'A',
101 soc_dev = soc_device_register(soc_dev_attr);
102 if (IS_ERR(soc_dev)) {
103 kfree(soc_dev_attr->family);
104 kfree(soc_dev_attr->soc_id);
105 kfree(soc_dev_attr->revision);
110 of_node_put(sun_top_ctrl);
113 arch_initcall(brcmstb_soc_device_init);