From fb0fd32a4d0337dc107cea52247029ed5cc6a4c2 Mon Sep 17 00:00:00 2001
From: Caleb Connolly <caleb.connolly@linaro.org>
Date: Mon, 15 Jul 2024 12:08:06 +0200
Subject: [PATCH] soc: qcom: cmd-db: adjust for U-Boot API

Keep the header pointer in the .data section so we don't initialize it
again after relocation, adjust cmd_db_get_header() to work with the
U-Boot API, and skip validating the header since all cmd-db users are
children of the rpmh-rsc and those children will only probe if cmd-db
initializes successfully.

Acked-by: Sumit Garg <sumit.garg@linaro.org>
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
 drivers/soc/qcom/cmd-db.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/soc/qcom/cmd-db.c b/drivers/soc/qcom/cmd-db.c
index f707aed59a..08736ea936 100644
--- a/drivers/soc/qcom/cmd-db.c
+++ b/drivers/soc/qcom/cmd-db.c
@@ -129,14 +129,10 @@ static int cmd_db_get_header(const char *id, const struct entry_header **eh,
 {
 	const struct rsc_hdr *rsc_hdr;
 	const struct entry_header *ent;
-	int ret, i, j;
+	int i, j;
 	u8 query[sizeof(ent->id)] __nonstring;
 
-	ret = cmd_db_ready();
-	if (ret)
-		return ret;
-
-	strtomem_pad(query, id, 0);
+	strncpy(query, id, sizeof(query));
 
 	for (i = 0; i < MAX_SLV_ID; i++) {
 		rsc_hdr = &cmd_db_header->header[i];
@@ -173,6 +169,13 @@ u32 cmd_db_read_addr(const char *id)
 	int ret;
 	const struct entry_header *ent;
 
+	debug("%s(%s)\n", __func__, id);
+
+	if (!cmd_db_header) {
+		log_err("%s: Command DB not initialized\n", __func__);
+		return 0;
+	}
+
 	ret = cmd_db_get_header(id, &ent, NULL);
 
 	return ret < 0 ? 0 : le32_to_cpu(ent->addr);
@@ -214,7 +217,7 @@ static const struct udevice_id cmd_db_ids[] = {
 U_BOOT_DRIVER(qcom_cmd_db) = {
 	.name		= "qcom_cmd_db",
 	.id		= UCLASS_MISC,
-	.probe		= cmd_db_bind,
+	.bind		= cmd_db_bind,
 	.of_match	= cmd_db_ids,
 };
 
-- 
2.39.5