diff mbox series

[v4,05/21] soc: qcom: cmd-db: replace cmd_db_ready() with cmd_db_init()

Message ID 20240709-b4-qcom-rpmh-v4-5-c06d0a26644a@linaro.org
State Superseded
Headers show
Series qcom: rpmh core and regulator support | expand

Commit Message

Caleb Connolly July 9, 2024, 9:34 a.m. UTC
Using the driver model for cmd-db is fine, but it's unnecessary
complexity which we can just avoid in U-Boot. Instead let's just have a
function to initialize it and call said function when initializing rpmh.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
 drivers/soc/qcom/cmd-db.c | 74 ++++++++++++++---------------------------------
 include/soc/qcom/cmd-db.h |  4 +--
 2 files changed, 24 insertions(+), 54 deletions(-)
diff mbox series

Patch

diff --git a/drivers/soc/qcom/cmd-db.c b/drivers/soc/qcom/cmd-db.c
index b6426ac3cafc..4d3fd4db8852 100644
--- a/drivers/soc/qcom/cmd-db.c
+++ b/drivers/soc/qcom/cmd-db.c
@@ -122,24 +122,8 @@  rsc_offset(const struct rsc_hdr *hdr, const struct entry_header *ent)
 
 	return cmd_db_header->data + offset + loffset;
 }
 
-/**
- * cmd_db_ready - Indicates if command DB is available
- *
- * Return: 0 on success, errno otherwise
- */
-int cmd_db_ready(void)
-{
-	if (cmd_db_header == NULL)
-		return -EPROBE_DEFER;
-	else if (!cmd_db_magic_matches(cmd_db_header))
-		return -EINVAL;
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(cmd_db_ready);
-
 static int cmd_db_get_header(const char *id, const struct entry_header **eh,
 			     const struct rsc_hdr **rh)
 {
 	const struct rsc_hdr *rsc_hdr;
@@ -193,55 +177,41 @@  u32 cmd_db_read_addr(const char *id)
 	return ret < 0 ? 0 : le32_to_cpu(ent->addr);
 }
 EXPORT_SYMBOL_GPL(cmd_db_read_addr);
 
-static int cmd_db_dev_probe(struct platform_device *pdev)
+int cmd_db_init(void)
 {
-	struct reserved_mem *rmem;
-	int ret = 0;
+	void __iomem *base;
+	ofnode rmem, node;
 
-	rmem = of_reserved_mem_lookup(pdev->dev.of_node);
-	if (!rmem) {
-		dev_err(&pdev->dev, "failed to acquire memory region\n");
-		return -EINVAL;
+	if (cmd_db_header)
+		return 0;
+
+	rmem = ofnode_path("/reserved-memory");
+	ofnode_for_each_subnode(node, rmem) {
+		if (ofnode_device_is_compatible(node, "qcom,cmd-db"))
+			goto found;
 	}
 
-	cmd_db_header = memremap(rmem->base, rmem->size, MEMREMAP_WB);
-	if (!cmd_db_header) {
-		ret = -ENOMEM;
-		cmd_db_header = NULL;
-		return ret;
+	log_err("%s: Failed to find cmd-db node\n", __func__);
+	return -ENOENT;
+found:
+	debug("%s(%s)\n", __func__, ofnode_get_name(node));
+
+	base = (void __iomem *)ofnode_get_addr(node);
+	if ((fdt_addr_t)base == FDT_ADDR_T_NONE) {
+		log_err("%s: Failed to read base address\n", __func__);
+		return -ENOENT;
 	}
 
+	cmd_db_header = base;
 	if (!cmd_db_magic_matches(cmd_db_header)) {
-		dev_err(&pdev->dev, "Invalid Command DB Magic\n");
+		log_err("%s: Invalid Command DB Magic\n", __func__);
 		return -EINVAL;
 	}
 
-	device_set_pm_not_required(&pdev->dev);
-
 	return 0;
 }
-
-static const struct of_device_id cmd_db_match_table[] = {
-	{ .compatible = "qcom,cmd-db" },
-	{ }
-};
-MODULE_DEVICE_TABLE(of, cmd_db_match_table);
-
-static struct platform_driver cmd_db_dev_driver = {
-	.probe  = cmd_db_dev_probe,
-	.driver = {
-		   .name = "cmd-db",
-		   .of_match_table = cmd_db_match_table,
-		   .suppress_bind_attrs = true,
-	},
-};
-
-static int __init cmd_db_device_init(void)
-{
-	return platform_driver_register(&cmd_db_dev_driver);
-}
-core_initcall(cmd_db_device_init);
+EXPORT_SYMBOL(cmd_db_init);
 
 MODULE_DESCRIPTION("Qualcomm Technologies, Inc. Command DB Driver");
 MODULE_LICENSE("GPL v2");
diff --git a/include/soc/qcom/cmd-db.h b/include/soc/qcom/cmd-db.h
index 753c7923f8e5..535164cc7fb0 100644
--- a/include/soc/qcom/cmd-db.h
+++ b/include/soc/qcom/cmd-db.h
@@ -21,13 +21,13 @@  enum cmd_db_hw_type {
 
 #if IS_ENABLED(CONFIG_QCOM_COMMAND_DB)
 u32 cmd_db_read_addr(const char *resource_id);
 
-int cmd_db_ready(void);
+int cmd_db_init(void);
 #else
 static inline u32 cmd_db_read_addr(const char *resource_id)
 { return 0; }
 
-static inline int cmd_db_ready(void)
+static inline int cmd_db_init(void)
 { return -ENODEV; }
 #endif /* CONFIG_QCOM_COMMAND_DB */
 #endif /* __QCOM_COMMAND_DB_H__ */