Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright © 2014 NVIDIA Corporation
0004  * Copyright © 2015 Broadcom Corporation
0005  */
0006 
0007 #include <linux/io.h>
0008 #include <linux/of.h>
0009 #include <linux/of_address.h>
0010 #include <linux/slab.h>
0011 #include <linux/soc/brcmstb/brcmstb.h>
0012 #include <linux/sys_soc.h>
0013 
0014 static u32 family_id;
0015 static u32 product_id;
0016 
0017 u32 brcmstb_get_family_id(void)
0018 {
0019     return family_id;
0020 }
0021 EXPORT_SYMBOL(brcmstb_get_family_id);
0022 
0023 u32 brcmstb_get_product_id(void)
0024 {
0025     return product_id;
0026 }
0027 EXPORT_SYMBOL(brcmstb_get_product_id);
0028 
0029 static const struct of_device_id sun_top_ctrl_match[] = {
0030     { .compatible = "brcm,bcm7125-sun-top-ctrl", },
0031     { .compatible = "brcm,bcm7346-sun-top-ctrl", },
0032     { .compatible = "brcm,bcm7358-sun-top-ctrl", },
0033     { .compatible = "brcm,bcm7360-sun-top-ctrl", },
0034     { .compatible = "brcm,bcm7362-sun-top-ctrl", },
0035     { .compatible = "brcm,bcm7420-sun-top-ctrl", },
0036     { .compatible = "brcm,bcm7425-sun-top-ctrl", },
0037     { .compatible = "brcm,bcm7429-sun-top-ctrl", },
0038     { .compatible = "brcm,bcm7435-sun-top-ctrl", },
0039     { .compatible = "brcm,brcmstb-sun-top-ctrl", },
0040     { }
0041 };
0042 
0043 static int __init brcmstb_soc_device_early_init(void)
0044 {
0045     struct device_node *sun_top_ctrl;
0046     void __iomem *sun_top_ctrl_base;
0047     int ret = 0;
0048 
0049     /* We could be on a multi-platform kernel, don't make this fatal but
0050      * bail out early
0051      */
0052     sun_top_ctrl = of_find_matching_node(NULL, sun_top_ctrl_match);
0053     if (!sun_top_ctrl)
0054         return ret;
0055 
0056     sun_top_ctrl_base = of_iomap(sun_top_ctrl, 0);
0057     if (!sun_top_ctrl_base) {
0058         ret = -ENODEV;
0059         goto out;
0060     }
0061 
0062     family_id = readl(sun_top_ctrl_base);
0063     product_id = readl(sun_top_ctrl_base + 0x4);
0064     iounmap(sun_top_ctrl_base);
0065 out:
0066     of_node_put(sun_top_ctrl);
0067     return ret;
0068 }
0069 early_initcall(brcmstb_soc_device_early_init);
0070 
0071 static int __init brcmstb_soc_device_init(void)
0072 {
0073     struct soc_device_attribute *soc_dev_attr;
0074     struct device_node *sun_top_ctrl;
0075     struct soc_device *soc_dev;
0076     int ret = 0;
0077 
0078     /* We could be on a multi-platform kernel, don't make this fatal but
0079      * bail out early
0080      */
0081     sun_top_ctrl = of_find_matching_node(NULL, sun_top_ctrl_match);
0082     if (!sun_top_ctrl)
0083         return ret;
0084 
0085     soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
0086     if (!soc_dev_attr) {
0087         ret = -ENOMEM;
0088         goto out;
0089     }
0090 
0091     soc_dev_attr->family = kasprintf(GFP_KERNEL, "%x",
0092                      family_id >> 28 ?
0093                      family_id >> 16 : family_id >> 8);
0094     soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%x",
0095                      product_id >> 28 ?
0096                      product_id >> 16 : product_id >> 8);
0097     soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%c%d",
0098                      ((product_id & 0xf0) >> 4) + 'A',
0099                        product_id & 0xf);
0100 
0101     soc_dev = soc_device_register(soc_dev_attr);
0102     if (IS_ERR(soc_dev)) {
0103         kfree(soc_dev_attr->family);
0104         kfree(soc_dev_attr->soc_id);
0105         kfree(soc_dev_attr->revision);
0106         kfree(soc_dev_attr);
0107         ret = -ENOMEM;
0108     }
0109 out:
0110     of_node_put(sun_top_ctrl);
0111     return ret;
0112 }
0113 arch_initcall(brcmstb_soc_device_init);