smd-rpm.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * RPM over SMD communication wrapper for interconnects
  4. *
  5. * Copyright (C) 2019 Linaro Ltd
  6. * Author: Georgi Djakov <georgi.djakov@linaro.org>
  7. */
  8. #include <linux/interconnect-provider.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/of_platform.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/soc/qcom/smd-rpm.h>
  14. #include "smd-rpm.h"
  15. #define RPM_KEY_BW 0x00007762
  16. static struct qcom_smd_rpm *icc_smd_rpm;
  17. struct icc_rpm_smd_req {
  18. __le32 key;
  19. __le32 nbytes;
  20. __le32 value;
  21. };
  22. bool qcom_icc_rpm_smd_available(void)
  23. {
  24. return !!icc_smd_rpm;
  25. }
  26. EXPORT_SYMBOL_GPL(qcom_icc_rpm_smd_available);
  27. int qcom_icc_rpm_smd_send(int ctx, int rsc_type, int id, u32 val)
  28. {
  29. struct icc_rpm_smd_req req = {
  30. .key = cpu_to_le32(RPM_KEY_BW),
  31. .nbytes = cpu_to_le32(sizeof(u32)),
  32. .value = cpu_to_le32(val),
  33. };
  34. return qcom_rpm_smd_write(icc_smd_rpm, ctx, rsc_type, id, &req,
  35. sizeof(req));
  36. }
  37. EXPORT_SYMBOL_GPL(qcom_icc_rpm_smd_send);
  38. static int qcom_icc_rpm_smd_remove(struct platform_device *pdev)
  39. {
  40. icc_smd_rpm = NULL;
  41. return 0;
  42. }
  43. static int qcom_icc_rpm_smd_probe(struct platform_device *pdev)
  44. {
  45. icc_smd_rpm = dev_get_drvdata(pdev->dev.parent);
  46. if (!icc_smd_rpm) {
  47. dev_err(&pdev->dev, "unable to retrieve handle to RPM\n");
  48. return -ENODEV;
  49. }
  50. return 0;
  51. }
  52. static struct platform_driver qcom_interconnect_rpm_smd_driver = {
  53. .driver = {
  54. .name = "icc_smd_rpm",
  55. },
  56. .probe = qcom_icc_rpm_smd_probe,
  57. .remove = qcom_icc_rpm_smd_remove,
  58. };
  59. module_platform_driver(qcom_interconnect_rpm_smd_driver);
  60. MODULE_AUTHOR("Georgi Djakov <georgi.djakov@linaro.org>");
  61. MODULE_DESCRIPTION("Qualcomm SMD RPM interconnect proxy driver");
  62. MODULE_LICENSE("GPL v2");
  63. MODULE_ALIAS("platform:icc_smd_rpm");