2
0

0050-v6.6-soc-qcom-Add-RPM-processor-subsystem-driver.patch 4.2 KB

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