From 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Fri, 10 May 2024 07:44:59 +0000
Subject: [PATCH] gmac get mac form eeprom

---
 kernel/drivers/soc/rockchip/rockchip_pvtm.c |  299 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 242 insertions(+), 57 deletions(-)

diff --git a/kernel/drivers/soc/rockchip/rockchip_pvtm.c b/kernel/drivers/soc/rockchip/rockchip_pvtm.c
index d9ff745..7500673 100644
--- a/kernel/drivers/soc/rockchip/rockchip_pvtm.c
+++ b/kernel/drivers/soc/rockchip/rockchip_pvtm.c
@@ -77,13 +77,13 @@
 	struct thermal_zone_device *tz;
 	const struct rockchip_pvtm_info *info;
 	const struct rockchip_pvtm_ops *ops;
+	struct dentry *dentry;
 };
 
 static LIST_HEAD(pvtm_list);
 
 #ifdef CONFIG_DEBUG_FS
-
-static struct dentry *rootdir;
+static struct dentry *rockchip_pvtm_debugfs_root;
 
 static int pvtm_value_show(struct seq_file *s, void *data)
 {
@@ -125,44 +125,63 @@
 	.release	= single_release,
 };
 
-static int __init pvtm_debug_init(void)
+static int rockchip_pvtm_debugfs_init(void)
 {
-	struct dentry *dentry, *d;
-	struct rockchip_pvtm *pvtm;
-
-	rootdir = debugfs_create_dir("pvtm", NULL);
-	if (!rootdir) {
+	rockchip_pvtm_debugfs_root = debugfs_create_dir("pvtm", NULL);
+	if (IS_ERR_OR_NULL(rockchip_pvtm_debugfs_root)) {
 		pr_err("Failed to create pvtm debug directory\n");
+		rockchip_pvtm_debugfs_root = NULL;
 		return -ENOMEM;
-	}
-
-	if (list_empty(&pvtm_list)) {
-		pr_info("pvtm list NULL\n");
-		return 0;
-	}
-
-	list_for_each_entry(pvtm, &pvtm_list, node) {
-		dentry = debugfs_create_dir(pvtm->info->name, rootdir);
-		if (!dentry) {
-			dev_err(pvtm->dev, "failed to creat pvtm %s debug dir\n",
-				pvtm->info->name);
-			return -ENOMEM;
-		}
-
-		d = debugfs_create_file("value", 0444, dentry,
-					(void *)pvtm, &pvtm_value_fops);
-		if (!d) {
-			dev_err(pvtm->dev, "failed to pvtm %s value node\n",
-				pvtm->info->name);
-			return -ENOMEM;
-		}
 	}
 
 	return 0;
 }
 
-late_initcall(pvtm_debug_init);
+static void rockchip_pvtm_debugfs_exit(void)
+{
+	debugfs_remove_recursive(rockchip_pvtm_debugfs_root);
+}
 
+static int rockchip_pvtm_add_debugfs(struct rockchip_pvtm *pvtm)
+{
+	struct dentry *d;
+
+	if (!rockchip_pvtm_debugfs_root)
+		return 0;
+
+	pvtm->dentry = debugfs_create_dir(pvtm->info->name,
+					  rockchip_pvtm_debugfs_root);
+	if (!pvtm->dentry) {
+		dev_err(pvtm->dev, "failed to create pvtm %s debug dir\n",
+			pvtm->info->name);
+		return -ENOMEM;
+	}
+
+	d = debugfs_create_file("value", 0444, pvtm->dentry,
+				(void *)pvtm, &pvtm_value_fops);
+	if (!d) {
+		dev_err(pvtm->dev, "failed to pvtm %s value node\n",
+			pvtm->info->name);
+		debugfs_remove_recursive(pvtm->dentry);
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+#else
+static inline int rockchip_pvtm_debugfs_init(void)
+{
+	return 0;
+}
+
+static inline void rockchip_pvtm_debugfs_exit(void)
+{
+}
+
+static inline int rockchip_pvtm_add_debugfs(struct rockchip_pvtm *pvtm)
+{
+	return 0;
+}
 #endif
 
 static int rockchip_pvtm_reset(struct rockchip_pvtm *pvtm)
@@ -332,6 +351,12 @@
 	clk_bulk_disable_unprepare(pvtm->num_clks, pvtm->clks);
 
 	return val;
+}
+
+static void rv1106_core_pvtm_set_ring_sel(struct rockchip_pvtm *pvtm,
+					  unsigned int ring_sel)
+{
+	writel_relaxed(wr_mask_bit(ring_sel + 4, 0x2, 0x7), pvtm->base + pvtm->con);
 }
 
 static void rv1126_pvtm_set_ring_sel(struct rockchip_pvtm *pvtm,
@@ -582,6 +607,124 @@
 	},
 };
 
+static const struct rockchip_pvtm_info rk3588_bigcore0_pvtm_infos[] = {
+	PVTM(0, "bigcore0", 7, 0, 1, 0x4, 0, 0x4),
+};
+
+static const struct rockchip_pvtm_data rk3588_bigcore0_pvtm = {
+	.con = 0x4,
+	.sta = 0x80,
+	.num_pvtms = ARRAY_SIZE(rk3588_bigcore0_pvtm_infos),
+	.infos = rk3588_bigcore0_pvtm_infos,
+	.ops = {
+		.get_value = rv1126_pvtm_get_value,
+		.set_ring_sel = rv1126_pvtm_set_ring_sel,
+	},
+};
+
+static const struct rockchip_pvtm_info rk3588_bigcore1_pvtm_infos[] = {
+	PVTM(1, "bigcore1", 7, 0, 1, 0x4, 0, 0x4),
+};
+
+static const struct rockchip_pvtm_data rk3588_bigcore1_pvtm = {
+	.con = 0x4,
+	.sta = 0x80,
+	.num_pvtms = ARRAY_SIZE(rk3588_bigcore1_pvtm_infos),
+	.infos = rk3588_bigcore1_pvtm_infos,
+	.ops = {
+		.get_value = rv1126_pvtm_get_value,
+		.set_ring_sel = rv1126_pvtm_set_ring_sel,
+	},
+};
+
+static const struct rockchip_pvtm_info rk3588_litcore_pvtm_infos[] = {
+	PVTM(2, "litcore", 7, 0, 1, 0x4, 0, 0x4),
+};
+
+static const struct rockchip_pvtm_data rk3588_litcore_pvtm = {
+	.con = 0x4,
+	.sta = 0x80,
+	.num_pvtms = ARRAY_SIZE(rk3588_litcore_pvtm_infos),
+	.infos = rk3588_litcore_pvtm_infos,
+	.ops = {
+		.get_value = rv1126_pvtm_get_value,
+		.set_ring_sel = rv1126_pvtm_set_ring_sel,
+	},
+};
+
+static const struct rockchip_pvtm_info rk3588_npu_pvtm_infos[] = {
+	PVTM(3, "npu", 2, 0, 1, 0x4, 0, 0x4),
+};
+
+static const struct rockchip_pvtm_data rk3588_npu_pvtm = {
+	.con = 0x4,
+	.sta = 0x80,
+	.num_pvtms = ARRAY_SIZE(rk3588_npu_pvtm_infos),
+	.infos = rk3588_npu_pvtm_infos,
+	.ops = {
+		.get_value = rv1126_pvtm_get_value,
+		.set_ring_sel = rv1126_pvtm_set_ring_sel,
+	},
+};
+
+static const struct rockchip_pvtm_info rk3588_gpu_pvtm_infos[] = {
+	PVTM(4, "gpu", 2, 0, 1, 0x4, 0, 0x4),
+};
+
+static const struct rockchip_pvtm_data rk3588_gpu_pvtm = {
+	.con = 0x4,
+	.sta = 0x80,
+	.num_pvtms = ARRAY_SIZE(rk3588_gpu_pvtm_infos),
+	.infos = rk3588_gpu_pvtm_infos,
+	.ops = {
+		.get_value = rv1126_pvtm_get_value,
+		.set_ring_sel = rv1126_pvtm_set_ring_sel,
+	},
+};
+
+static const struct rockchip_pvtm_info rk3588_pmu_pvtm_infos[] = {
+	PVTM(5, "pmu", 1, 0, 1, 0x4, 0, 0x4),
+};
+
+static const struct rockchip_pvtm_data rk3588_pmu_pvtm = {
+	.con = 0x4,
+	.sta = 0x80,
+	.num_pvtms = ARRAY_SIZE(rk3588_pmu_pvtm_infos),
+	.infos = rk3588_pmu_pvtm_infos,
+	.ops = {
+		.get_value = rv1126_pvtm_get_value,
+	},
+};
+
+static const struct rockchip_pvtm_info rv1106_corepvtm_infos[] = {
+	PVTM(0, "core", 2, 0, 1, 0x4, 0, 0x4),
+};
+
+static const struct rockchip_pvtm_data rv1106_corepvtm = {
+	.con = 0x4,
+	.sta = 0x80,
+	.num_pvtms = ARRAY_SIZE(rv1106_corepvtm_infos),
+	.infos = rv1106_corepvtm_infos,
+	.ops = {
+		.get_value = rv1126_pvtm_get_value,
+		.set_ring_sel = rv1106_core_pvtm_set_ring_sel,
+	},
+};
+
+static const struct rockchip_pvtm_info rv1106_pmupvtm_infos[] = {
+	PVTM(1, "pmu", 1, 0, 1, 0x4, 0, 0x4),
+};
+
+static const struct rockchip_pvtm_data rv1106_pmupvtm = {
+	.con = 0x4,
+	.sta = 0x80,
+	.num_pvtms = ARRAY_SIZE(rv1106_pmupvtm_infos),
+	.infos = rv1106_pmupvtm_infos,
+	.ops = {
+		.get_value = rv1126_pvtm_get_value,
+	},
+};
+
 static const struct rockchip_pvtm_info rv1126_cpupvtm_infos[] = {
 	PVTM(0, "cpu", 7, 0, 1, 0x4, 0, 0x4),
 };
@@ -691,6 +834,42 @@
 		.data = (void *)&rk3568_npupvtm,
 	},
 #endif
+#ifdef CONFIG_CPU_RK3588
+	{
+		.compatible = "rockchip,rk3588-bigcore0-pvtm",
+		.data = (void *)&rk3588_bigcore0_pvtm,
+	},
+	{
+		.compatible = "rockchip,rk3588-bigcore1-pvtm",
+		.data = (void *)&rk3588_bigcore1_pvtm,
+	},
+	{
+		.compatible = "rockchip,rk3588-litcore-pvtm",
+		.data = (void *)&rk3588_litcore_pvtm,
+	},
+	{
+		.compatible = "rockchip,rk3588-gpu-pvtm",
+		.data = (void *)&rk3588_gpu_pvtm,
+	},
+	{
+		.compatible = "rockchip,rk3588-npu-pvtm",
+		.data = (void *)&rk3588_npu_pvtm,
+	},
+	{
+		.compatible = "rockchip,rk3588-pmu-pvtm",
+		.data = (void *)&rk3588_pmu_pvtm,
+	},
+#endif
+#ifdef CONFIG_CPU_RV1106
+	{
+		.compatible = "rockchip,rv1106-core-pvtm",
+		.data = (void *)&rv1106_corepvtm,
+	},
+	{
+		.compatible = "rockchip,rv1106-pmu-pvtm",
+		.data = (void *)&rv1106_pmupvtm,
+	},
+#endif
 #ifdef CONFIG_CPU_RV1126
 	{
 		.compatible = "rockchip,rv1126-cpu-pvtm",
@@ -731,7 +910,8 @@
 {
 	struct rockchip_pvtm *pvtm;
 	const char *tz_name;
-	u32 id, index, i;
+	u32 id, index;
+	int i;
 
 	if (of_property_read_u32(node, "reg", &id)) {
 		dev_err(dev, "%s: failed to retrieve pvtm id\n", node->name);
@@ -765,18 +945,18 @@
 	pvtm->num_clks = of_clk_get_parent_count(node);
 	if (pvtm->num_clks <= 0) {
 		dev_err(dev, "%s: does not have clocks\n", node->name);
-		return NULL;
+		goto clk_num_err;
 	}
 	pvtm->clks = devm_kcalloc(dev, pvtm->num_clks, sizeof(*pvtm->clks),
 				  GFP_KERNEL);
 	if (!pvtm->clks)
-		return NULL;
+		goto clk_num_err;
 	for (i = 0; i < pvtm->num_clks; i++) {
 		pvtm->clks[i].clk = of_clk_get(node, i);
 		if (IS_ERR(pvtm->clks[i].clk)) {
 			dev_err(dev, "%s: failed to get clk at index %d\n",
 				node->name, i);
-			return NULL;
+			goto clk_err;
 		}
 	}
 
@@ -784,23 +964,18 @@
 	if (IS_ERR(pvtm->rst))
 		dev_dbg(dev, "%s: failed to get reset\n", node->name);
 
+	rockchip_pvtm_add_debugfs(pvtm);
+
 	return pvtm;
-}
 
-static void rockchip_del_pvtm(const struct rockchip_pvtm_data *data)
-{
-	struct rockchip_pvtm *pvtm, *tmp;
-	int i;
+clk_err:
+	while (--i >= 0)
+		clk_put(pvtm->clks[i].clk);
+	devm_kfree(dev, pvtm->clks);
+clk_num_err:
+	devm_kfree(dev, pvtm);
 
-	if (list_empty(&pvtm_list))
-		return;
-
-	for (i = 0; i < data->num_pvtms; i++) {
-		list_for_each_entry_safe(pvtm, tmp, &pvtm_list, node) {
-			if (pvtm->info->id == data->infos[i].id)
-				list_del(&pvtm->node);
-		}
-	}
+	return NULL;
 }
 
 static int rockchip_pvtm_probe(struct platform_device *pdev)
@@ -832,18 +1007,15 @@
 	for_each_available_child_of_node(np, node) {
 		pvtm = rockchip_pvtm_init(dev, node, match->data, grf, base);
 		if (!pvtm) {
-			dev_err(dev, "failed to handle node %s\n", node->name);
-			goto error;
+			dev_err(dev, "failed to handle node %s\n",
+				node->full_name);
+			continue;
 		}
 		list_add(&pvtm->node, &pvtm_list);
+		dev_info(dev, "%s probed\n", node->full_name);
 	}
 
 	return 0;
-
-error:
-	rockchip_del_pvtm(match->data);
-
-	return -EINVAL;
 }
 
 static struct platform_driver rockchip_pvtm_driver = {
@@ -854,7 +1026,20 @@
 	},
 };
 
-module_platform_driver(rockchip_pvtm_driver);
+static int __init rockchip_pvtm_module_init(void)
+{
+	rockchip_pvtm_debugfs_init();
+
+	return platform_driver_register(&rockchip_pvtm_driver);
+}
+module_init(rockchip_pvtm_module_init);
+
+static void __exit rockchip_pvtm_module_exit(void)
+{
+	rockchip_pvtm_debugfs_exit();
+	platform_driver_unregister(&rockchip_pvtm_driver);
+}
+module_exit(rockchip_pvtm_module_exit);
 
 MODULE_DESCRIPTION("Rockchip PVTM driver");
 MODULE_AUTHOR("Finley Xiao <finley.xiao@rock-chips.com>");

--
Gitblit v1.6.2