Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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