common.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright © 2014 NVIDIA Corporation
  4. * Copyright © 2015 Broadcom Corporation
  5. */
  6. #include <linux/io.h>
  7. #include <linux/of.h>
  8. #include <linux/of_address.h>
  9. #include <linux/slab.h>
  10. #include <linux/soc/brcmstb/brcmstb.h>
  11. #include <linux/sys_soc.h>
  12. static u32 family_id;
  13. static u32 product_id;
  14. u32 brcmstb_get_family_id(void)
  15. {
  16. return family_id;
  17. }
  18. EXPORT_SYMBOL(brcmstb_get_family_id);
  19. u32 brcmstb_get_product_id(void)
  20. {
  21. return product_id;
  22. }
  23. EXPORT_SYMBOL(brcmstb_get_product_id);
  24. static const struct of_device_id sun_top_ctrl_match[] = {
  25. { .compatible = "brcm,bcm7125-sun-top-ctrl", },
  26. { .compatible = "brcm,bcm7346-sun-top-ctrl", },
  27. { .compatible = "brcm,bcm7358-sun-top-ctrl", },
  28. { .compatible = "brcm,bcm7360-sun-top-ctrl", },
  29. { .compatible = "brcm,bcm7362-sun-top-ctrl", },
  30. { .compatible = "brcm,bcm7420-sun-top-ctrl", },
  31. { .compatible = "brcm,bcm7425-sun-top-ctrl", },
  32. { .compatible = "brcm,bcm7429-sun-top-ctrl", },
  33. { .compatible = "brcm,bcm7435-sun-top-ctrl", },
  34. { .compatible = "brcm,brcmstb-sun-top-ctrl", },
  35. { }
  36. };
  37. static int __init brcmstb_soc_device_early_init(void)
  38. {
  39. struct device_node *sun_top_ctrl;
  40. void __iomem *sun_top_ctrl_base;
  41. int ret = 0;
  42. /* We could be on a multi-platform kernel, don't make this fatal but
  43. * bail out early
  44. */
  45. sun_top_ctrl = of_find_matching_node(NULL, sun_top_ctrl_match);
  46. if (!sun_top_ctrl)
  47. return ret;
  48. sun_top_ctrl_base = of_iomap(sun_top_ctrl, 0);
  49. if (!sun_top_ctrl_base) {
  50. ret = -ENODEV;
  51. goto out;
  52. }
  53. family_id = readl(sun_top_ctrl_base);
  54. product_id = readl(sun_top_ctrl_base + 0x4);
  55. iounmap(sun_top_ctrl_base);
  56. out:
  57. of_node_put(sun_top_ctrl);
  58. return ret;
  59. }
  60. early_initcall(brcmstb_soc_device_early_init);
  61. static int __init brcmstb_soc_device_init(void)
  62. {
  63. struct soc_device_attribute *soc_dev_attr;
  64. struct device_node *sun_top_ctrl;
  65. struct soc_device *soc_dev;
  66. int ret = 0;
  67. /* We could be on a multi-platform kernel, don't make this fatal but
  68. * bail out early
  69. */
  70. sun_top_ctrl = of_find_matching_node(NULL, sun_top_ctrl_match);
  71. if (!sun_top_ctrl)
  72. return ret;
  73. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  74. if (!soc_dev_attr) {
  75. ret = -ENOMEM;
  76. goto out;
  77. }
  78. soc_dev_attr->family = kasprintf(GFP_KERNEL, "%x",
  79. family_id >> 28 ?
  80. family_id >> 16 : family_id >> 8);
  81. soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%x",
  82. product_id >> 28 ?
  83. product_id >> 16 : product_id >> 8);
  84. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%c%d",
  85. ((product_id & 0xf0) >> 4) + 'A',
  86. product_id & 0xf);
  87. soc_dev = soc_device_register(soc_dev_attr);
  88. if (IS_ERR(soc_dev)) {
  89. kfree(soc_dev_attr->family);
  90. kfree(soc_dev_attr->soc_id);
  91. kfree(soc_dev_attr->revision);
  92. kfree(soc_dev_attr);
  93. ret = -ENOMEM;
  94. }
  95. out:
  96. of_node_put(sun_top_ctrl);
  97. return ret;
  98. }
  99. arch_initcall(brcmstb_soc_device_init);