mediatek: mt7629: 6.6: disable LEDS_SMARTRG_LED by default
[openwrt/staging/stintel.git] / target / linux / qualcommax / patches-6.1 / 0050-v6.6-soc-qcom-Add-RPM-processor-subsystem-driver.patch
1 From 8ddfa81d090c71fd6cb3cb8ca1d420c0da33a575 Mon Sep 17 00:00:00 2001
2 From: Stephan Gerhold <stephan@gerhold.net>
3 Date: Thu, 15 Jun 2023 18:50:42 +0200
4 Subject: [PATCH] soc: qcom: Add RPM processor/subsystem driver
5
6 Add a simple driver for the qcom,rpm-proc compatible that registers the
7 "smd-edge" and populates other children defined in the device tree.
8
9 Note that the DT schema belongs to the remoteproc subsystem while this
10 driver is added inside soc/qcom. I argue that the RPM *is* a remoteproc,
11 but as an implementation detail in Linux it can currently not benefit
12 from anything provided by the remoteproc subsystem. The RPM firmware is
13 usually already loaded and started by earlier components in the boot
14 chain and is not meant to be ever restarted.
15
16 To avoid breaking existing kernel configurations the driver is always
17 built when smd-rpm.c is also built. They belong closely together anyway.
18 To avoid build errors CONFIG_RPMSG_QCOM_SMD must be also built-in if
19 rpm-proc is.
20
21 Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
22 Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
23 Link: https://lore.kernel.org/r/20230531-rpm-rproc-v3-9-a07dcdefd918@gerhold.net
24 Signed-off-by: Bjorn Andersson <andersson@kernel.org>
25 ---
26 drivers/soc/qcom/Kconfig | 1 +
27 drivers/soc/qcom/Makefile | 2 +-
28 drivers/soc/qcom/rpm-proc.c | 77 +++++++++++++++++++++++++++++++++++++
29 3 files changed, 79 insertions(+), 1 deletion(-)
30 create mode 100644 drivers/soc/qcom/rpm-proc.c
31
32 --- a/drivers/soc/qcom/Kconfig
33 +++ b/drivers/soc/qcom/Kconfig
34 @@ -153,6 +153,7 @@ config QCOM_SMD_RPM
35 tristate "Qualcomm Resource Power Manager (RPM) over SMD"
36 depends on ARCH_QCOM || COMPILE_TEST
37 depends on RPMSG
38 + depends on RPMSG_QCOM_SMD || RPMSG_QCOM_SMD=n
39 help
40 If you say yes to this option, support will be included for the
41 Resource Power Manager system found in the Qualcomm 8974 based
42 --- a/drivers/soc/qcom/Makefile
43 +++ b/drivers/soc/qcom/Makefile
44 @@ -14,7 +14,7 @@ obj-$(CONFIG_QCOM_RMTFS_MEM) += rmtfs_me
45 obj-$(CONFIG_QCOM_RPMH) += qcom_rpmh.o
46 qcom_rpmh-y += rpmh-rsc.o
47 qcom_rpmh-y += rpmh.o
48 -obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o
49 +obj-$(CONFIG_QCOM_SMD_RPM) += rpm-proc.o smd-rpm.o
50 obj-$(CONFIG_QCOM_SMEM) += smem.o
51 obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
52 obj-$(CONFIG_QCOM_SMP2P) += smp2p.o
53 --- /dev/null
54 +++ b/drivers/soc/qcom/rpm-proc.c
55 @@ -0,0 +1,77 @@
56 +// SPDX-License-Identifier: GPL-2.0-only
57 +/* Copyright (c) 2021-2023, Stephan Gerhold <stephan@gerhold.net> */
58 +
59 +#include <linux/module.h>
60 +#include <linux/of.h>
61 +#include <linux/of_platform.h>
62 +#include <linux/platform_device.h>
63 +#include <linux/rpmsg/qcom_smd.h>
64 +
65 +static int rpm_proc_probe(struct platform_device *pdev)
66 +{
67 + struct qcom_smd_edge *edge = NULL;
68 + struct device *dev = &pdev->dev;
69 + struct device_node *edge_node;
70 + int ret;
71 +
72 + edge_node = of_get_child_by_name(dev->of_node, "smd-edge");
73 + if (edge_node) {
74 + edge = qcom_smd_register_edge(dev, edge_node);
75 + of_node_put(edge_node);
76 + if (IS_ERR(edge))
77 + return dev_err_probe(dev, PTR_ERR(edge),
78 + "Failed to register smd-edge\n");
79 + }
80 +
81 + ret = devm_of_platform_populate(dev);
82 + if (ret) {
83 + dev_err(dev, "Failed to populate child devices: %d\n", ret);
84 + goto err;
85 + }
86 +
87 + platform_set_drvdata(pdev, edge);
88 + return 0;
89 +err:
90 + if (edge)
91 + qcom_smd_unregister_edge(edge);
92 + return ret;
93 +}
94 +
95 +static void rpm_proc_remove(struct platform_device *pdev)
96 +{
97 + struct qcom_smd_edge *edge = platform_get_drvdata(pdev);
98 +
99 + if (edge)
100 + qcom_smd_unregister_edge(edge);
101 +}
102 +
103 +static const struct of_device_id rpm_proc_of_match[] = {
104 + { .compatible = "qcom,rpm-proc", },
105 + { /* sentinel */ }
106 +};
107 +MODULE_DEVICE_TABLE(of, rpm_proc_of_match);
108 +
109 +static struct platform_driver rpm_proc_driver = {
110 + .probe = rpm_proc_probe,
111 + .remove_new = rpm_proc_remove,
112 + .driver = {
113 + .name = "qcom-rpm-proc",
114 + .of_match_table = rpm_proc_of_match,
115 + },
116 +};
117 +
118 +static int __init rpm_proc_init(void)
119 +{
120 + return platform_driver_register(&rpm_proc_driver);
121 +}
122 +arch_initcall(rpm_proc_init);
123 +
124 +static void __exit rpm_proc_exit(void)
125 +{
126 + platform_driver_unregister(&rpm_proc_driver);
127 +}
128 +module_exit(rpm_proc_exit);
129 +
130 +MODULE_DESCRIPTION("Qualcomm RPM processor/subsystem driver");
131 +MODULE_AUTHOR("Stephan Gerhold <stephan@gerhold.net>");
132 +MODULE_LICENSE("GPL");