ath79: add support for Huawei AP5030DN
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 830-03-v6.5-soc-qcom-smem-introduce-qcom_smem_get_soc_id.patch
1 From c3ecf2602a32d9b9e5fc997076c0d2836495c085 Mon Sep 17 00:00:00 2001
2 From: Robert Marko <robimarko@gmail.com>
3 Date: Fri, 26 May 2023 22:48:00 +0200
4 Subject: [PATCH] soc: qcom: smem: introduce qcom_smem_get_soc_id()
5
6 Introduce a helper to return the SoC SMEM ID, which is used to identify the
7 exact SoC model as there may be differences in the same SoC family.
8
9 Currently, cpufreq-nvmem does this completely in the driver and there has
10 been more interest expresed for other drivers to use this information so
11 lets expose a common helper to prevent redoing it in individual drivers
12 since this field is present on every SMEM table version.
13
14 Signed-off-by: Robert Marko <robimarko@gmail.com>
15 Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
16 Signed-off-by: Bjorn Andersson <andersson@kernel.org>
17 Link: https://lore.kernel.org/r/20230526204802.3081168-3-robimarko@gmail.com
18 ---
19 drivers/soc/qcom/smem.c | 23 +++++++++++++++++++++++
20 include/linux/soc/qcom/smem.h | 2 ++
21 2 files changed, 25 insertions(+)
22
23 --- a/drivers/soc/qcom/smem.c
24 +++ b/drivers/soc/qcom/smem.c
25 @@ -14,6 +14,7 @@
26 #include <linux/sizes.h>
27 #include <linux/slab.h>
28 #include <linux/soc/qcom/smem.h>
29 +#include <linux/soc/qcom/socinfo.h>
30
31 /*
32 * The Qualcomm shared memory system is a allocate only heap structure that
33 @@ -772,6 +773,28 @@ phys_addr_t qcom_smem_virt_to_phys(void
34 }
35 EXPORT_SYMBOL_GPL(qcom_smem_virt_to_phys);
36
37 +/**
38 + * qcom_smem_get_soc_id() - return the SoC ID
39 + * @id: On success, we return the SoC ID here.
40 + *
41 + * Look up SoC ID from HW/SW build ID and return it.
42 + *
43 + * Return: 0 on success, negative errno on failure.
44 + */
45 +int qcom_smem_get_soc_id(u32 *id)
46 +{
47 + struct socinfo *info;
48 +
49 + info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, NULL);
50 + if (IS_ERR(info))
51 + return PTR_ERR(info);
52 +
53 + *id = __le32_to_cpu(info->id);
54 +
55 + return 0;
56 +}
57 +EXPORT_SYMBOL_GPL(qcom_smem_get_soc_id);
58 +
59 static int qcom_smem_get_sbl_version(struct qcom_smem *smem)
60 {
61 struct smem_header *header;
62 --- a/include/linux/soc/qcom/smem.h
63 +++ b/include/linux/soc/qcom/smem.h
64 @@ -11,4 +11,6 @@ int qcom_smem_get_free_space(unsigned ho
65
66 phys_addr_t qcom_smem_virt_to_phys(void *p);
67
68 +int qcom_smem_get_soc_id(u32 *id);
69 +
70 #endif