From: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
To: Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
Loic Poulain <loic.poulain@linaro.org>,
Kalle Valo <kvalo@kernel.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
wcn36xx@lists.infradead.org, linux-wireless@vger.kernel.org,
linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org,
Arnd Bergmann <arnd@arndb.de>,
Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Subject: [PATCH 01/12] soc: qcom: add firmware name helper
Date: Tue, 21 May 2024 12:45:21 +0300 [thread overview]
Message-ID: <20240521-qcom-firmware-name-v1-1-99a6d32b1e5e@linaro.org> (raw)
In-Reply-To: <20240521-qcom-firmware-name-v1-0-99a6d32b1e5e@linaro.org>
Qualcomm platforms have different sets of the firmware files, which
differ from platform to platform (and from board to board, due to the
embedded signatures). Rather than listing all the firmware files,
including full paths, in the DT, provide a way to determine firmware
path based on the root DT node compatible.
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/soc/qcom/Kconfig | 5 +++
drivers/soc/qcom/Makefile | 1 +
drivers/soc/qcom/qcom_fw_helper.c | 86 ++++++++++++++++++++++++++++++++++++++
include/linux/soc/qcom/fw_helper.h | 10 +++++
4 files changed, 102 insertions(+)
diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index 5af33b0e3470..b663774d65f8 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -62,6 +62,11 @@ config QCOM_MDT_LOADER
tristate
select QCOM_SCM
+config QCOM_FW_HELPER
+ tristate "NONE FW HELPER"
+ help
+ Helpers to return platform-specific location for the firmware files.
+
config QCOM_OCMEM
tristate "Qualcomm On Chip Memory (OCMEM) driver"
depends on ARCH_QCOM
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index ca0bece0dfff..e612bee5b955 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_QCOM_GENI_SE) += qcom-geni-se.o
obj-$(CONFIG_QCOM_COMMAND_DB) += cmd-db.o
obj-$(CONFIG_QCOM_GSBI) += qcom_gsbi.o
obj-$(CONFIG_QCOM_MDT_LOADER) += mdt_loader.o
+obj-$(CONFIG_QCOM_FW_HELPER) += qcom_fw_helper.o
obj-$(CONFIG_QCOM_OCMEM) += ocmem.o
obj-$(CONFIG_QCOM_PDR_HELPERS) += pdr_interface.o
obj-$(CONFIG_QCOM_PMIC_GLINK) += pmic_glink.o
diff --git a/drivers/soc/qcom/qcom_fw_helper.c b/drivers/soc/qcom/qcom_fw_helper.c
new file mode 100644
index 000000000000..13123c2514b8
--- /dev/null
+++ b/drivers/soc/qcom/qcom_fw_helper.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Qualcomm Firmware loading data
+ *
+ * Copyright (C) 2024 Linaro Ltd
+ */
+
+#include <linux/cleanup.h>
+#include <linux/device.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/soc/qcom/fw_helper.h>
+
+static DEFINE_MUTEX(qcom_fw_mutex);
+static const char *fw_path;
+
+static const struct of_device_id qcom_fw_paths[] = {
+ /* device-specific entries */
+ { .compatible = "thundercomm,db845c", .data = "qcom/sdm845/Thundercomm/db845c", },
+ { .compatible = "qcom,qrb5165-rb5", .data = "qcom/sm8250/Thundercomm/RB5", },
+ /* SoC default entries */
+ { .compatible = "qcom,apq8016", .data = "qcom/apq8016", },
+ { .compatible = "qcom,apq8096", .data = "qcom/apq8096", },
+ { .compatible = "qcom,sdm845", .data = "qcom/sdm845", },
+ { .compatible = "qcom,sm8250", .data = "qcom/sm8250", },
+ { .compatible = "qcom,sm8350", .data = "qcom/sm8350", },
+ { .compatible = "qcom,sm8450", .data = "qcom/sm8450", },
+ { .compatible = "qcom,sm8550", .data = "qcom/sm8550", },
+ { .compatible = "qcom,sm8650", .data = "qcom/sm8650", },
+ {},
+};
+
+static int qcom_fw_ensure_init(void)
+{
+ const struct of_device_id *match;
+ struct device_node *root;
+
+ if (fw_path)
+ return 0;
+
+ root = of_find_node_by_path("/");
+ if (!root)
+ return -ENODEV;
+
+ match = of_match_node(qcom_fw_paths, root);
+ of_node_put(root);
+ if (!match || !match->data) {
+ pr_notice("Platform not supported by qcom_fw_helper\n");
+ return -ENODEV;
+ }
+
+ fw_path = match->data;
+
+ return 0;
+}
+
+const char *qcom_get_board_fw(const char *firmware)
+{
+ if (strchr(firmware, '/'))
+ return kstrdup(firmware, GFP_KERNEL);
+
+ scoped_guard(mutex, &qcom_fw_mutex) {
+ if (!qcom_fw_ensure_init())
+ return kasprintf(GFP_KERNEL, "%s/%s", fw_path, firmware);
+ }
+
+ return kstrdup(firmware, GFP_KERNEL);
+}
+EXPORT_SYMBOL_GPL(qcom_get_board_fw);
+
+const char *devm_qcom_get_board_fw(struct device *dev, const char *firmware)
+{
+ if (strchr(firmware, '/'))
+ return devm_kstrdup(dev, firmware, GFP_KERNEL);
+
+ scoped_guard(mutex, &qcom_fw_mutex) {
+ if (!qcom_fw_ensure_init())
+ return devm_kasprintf(dev, GFP_KERNEL, "%s/%s", fw_path, firmware);
+ }
+
+ return devm_kstrdup(dev, firmware, GFP_KERNEL);
+}
+EXPORT_SYMBOL_GPL(devm_qcom_get_board_fw);
+
+MODULE_DESCRIPTION("Firmware helpers for Qualcomm devices");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/soc/qcom/fw_helper.h b/include/linux/soc/qcom/fw_helper.h
new file mode 100644
index 000000000000..755645386bba
--- /dev/null
+++ b/include/linux/soc/qcom/fw_helper.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __QCOM_FW_HELPER_H__
+#define __QCOM_FW_HELPER_H__
+
+struct device;
+
+const char *qcom_get_board_fw(const char *firmware);
+const char *devm_qcom_get_board_fw(struct device *dev, const char *firmware);
+
+#endif
--
2.39.2
next prev parent reply other threads:[~2024-05-21 9:45 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-21 9:45 [PATCH 00/12] arm64: qcom: autodetect firmware paths Dmitry Baryshkov
2024-05-21 9:45 ` Dmitry Baryshkov [this message]
2024-05-21 9:52 ` [PATCH 01/12] soc: qcom: add firmware name helper neil.armstrong
2024-05-21 10:01 ` Dmitry Baryshkov
2024-05-21 11:20 ` Kalle Valo
2024-05-21 13:08 ` Dmitry Baryshkov
2024-05-22 22:48 ` Bjorn Andersson
2024-05-27 11:42 ` Dmitry Baryshkov
2024-05-29 2:28 ` Bjorn Andersson
2024-05-31 18:48 ` Kalle Valo
2024-05-21 9:45 ` [PATCH 02/12] wifi: wcn36xx: make use of QCOM_FW_HELPER Dmitry Baryshkov
2024-05-31 18:53 ` Kalle Valo
2024-05-21 9:45 ` [PATCH 03/12] soc: qcom: wcnss_ctrl: " Dmitry Baryshkov
2024-05-21 9:45 ` [PATCH 04/12] remoteproc: qcom_q6v5_mss: switch to mbn files by default Dmitry Baryshkov
2024-05-21 9:45 ` [PATCH 05/12] remoteproc: qcom_q6v5_mss: make use of QCOM_FW_HELPER Dmitry Baryshkov
2024-05-21 9:45 ` [PATCH 06/12] remoteproc: qcom_q6v5_pas: switch to mbn files by default Dmitry Baryshkov
2024-05-21 9:49 ` neil.armstrong
2024-05-21 10:01 ` Dmitry Baryshkov
2024-05-21 19:40 ` Bjorn Andersson
2024-05-21 9:45 ` [PATCH 07/12] remoteproc: qcom_q6v5_pas: make use of QCOM_FW_HELPER Dmitry Baryshkov
2024-05-21 9:45 ` [PATCH 08/12] remoteproc: qcom_wcnss: switch to mbn files by default Dmitry Baryshkov
2024-05-21 9:45 ` [PATCH 09/12] remoteproc: qcom_wcnss: make use of QCOM_FW_HELPER Dmitry Baryshkov
2024-05-22 19:21 ` Jeff Johnson
2024-05-22 20:42 ` Dmitry Baryshkov
2024-05-21 9:45 ` [PATCH 10/12] " Dmitry Baryshkov
2024-05-21 9:45 ` [PATCH 11/12] arm64: dts: qcom: apq8016-sbc: drop firmware-name properties Dmitry Baryshkov
2024-05-21 9:45 ` [PATCH 12/12] arm64: dts: qcom: apq8096-db820c: " Dmitry Baryshkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240521-qcom-firmware-name-v1-1-99a6d32b1e5e@linaro.org \
--to=dmitry.baryshkov@linaro.org \
--cc=andersson@kernel.org \
--cc=arnd@arndb.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=krzk+dt@kernel.org \
--cc=kvalo@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=loic.poulain@linaro.org \
--cc=mathieu.poirier@linaro.org \
--cc=robh@kernel.org \
--cc=wcn36xx@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).