mmrm_internal.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/types.h>
  7. #include <linux/of_platform.h>
  8. #include "mmrm_internal.h"
  9. #include "mmrm_debug.h"
  10. static struct mmrm_common_data common_pt_data[] = {
  11. {
  12. .key = "qcom,mmrm_clk_mgr_scheme",
  13. .value = CLK_MGR_SCHEME_SW,
  14. },
  15. };
  16. /*throttle client list is as per fdd & resource availability*/
  17. static struct mmrm_throttle_clients_data common_pt_throttle_clients_data_pineapple[] = {
  18. {
  19. .domain = MMRM_CLIENT_DOMAIN_DISPLAY,
  20. .id = 0x3e,
  21. },
  22. {
  23. .domain = MMRM_CLIENT_DOMAIN_VIDEO,
  24. .id = 0x03,
  25. },
  26. {
  27. .domain = MMRM_CLIENT_DOMAIN_CAMERA,
  28. .id = 0x58,
  29. },
  30. {
  31. .domain = MMRM_CLIENT_DOMAIN_CVP,
  32. .id = 0x0a,
  33. },
  34. {
  35. .domain = MMRM_CLIENT_DOMAIN_CAMERA,
  36. .id = 0x02,
  37. },
  38. };
  39. static struct mmrm_throttle_clients_data common_pt_throttle_clients_data_cliffs[] = {
  40. {
  41. .domain = MMRM_CLIENT_DOMAIN_DISPLAY,
  42. .id = 0x3e,
  43. },
  44. {
  45. .domain = MMRM_CLIENT_DOMAIN_VIDEO,
  46. .id = 0x03,
  47. },
  48. {
  49. .domain = MMRM_CLIENT_DOMAIN_CAMERA,
  50. .id = 0x62,
  51. },
  52. {
  53. .domain = MMRM_CLIENT_DOMAIN_CVP,
  54. .id = 0x0a,
  55. },
  56. {
  57. .domain = MMRM_CLIENT_DOMAIN_CAMERA,
  58. .id = 0x17,
  59. },
  60. };
  61. static struct mmrm_platform_data commom_pt_platform_data_pineapple = {
  62. .common_data = common_pt_data,
  63. .common_data_length = ARRAY_SIZE(common_pt_data),
  64. .throttle_clk_clients_data = common_pt_throttle_clients_data_pineapple,
  65. .throttle_clk_clients_data_length = ARRAY_SIZE(common_pt_throttle_clients_data_pineapple),
  66. };
  67. static struct mmrm_platform_data commom_pt_platform_data_cliffs = {
  68. .common_data = common_pt_data,
  69. .common_data_length = ARRAY_SIZE(common_pt_data),
  70. .throttle_clk_clients_data = common_pt_throttle_clients_data_cliffs,
  71. .throttle_clk_clients_data_length = ARRAY_SIZE(common_pt_throttle_clients_data_cliffs),
  72. };
  73. static const struct of_device_id mmrm_dt_match[] = {
  74. {
  75. .compatible = "qcom,waipio-mmrm",
  76. .data = &commom_pt_platform_data_pineapple,
  77. },
  78. {
  79. .compatible = "qcom,kalama-mmrm",
  80. .data = &commom_pt_platform_data_pineapple,
  81. },
  82. {
  83. .compatible = "qcom,pineapple-mmrm",
  84. .data = &commom_pt_platform_data_pineapple,
  85. },
  86. {
  87. .compatible = "qcom,cliffs-mmrm",
  88. .data = &commom_pt_platform_data_cliffs,
  89. },
  90. {},
  91. };
  92. struct mmrm_platform_data *mmrm_get_platform_data(struct device *dev)
  93. {
  94. struct mmrm_platform_data *platform_data = NULL;
  95. const struct of_device_id *match;
  96. match = of_match_node(mmrm_dt_match, dev->of_node);
  97. if (match)
  98. platform_data = (struct mmrm_platform_data *)match->data;
  99. if (!platform_data)
  100. goto exit;
  101. /* add additional config checks for platform data */
  102. exit:
  103. return platform_data;
  104. }
  105. int mmrm_init(struct mmrm_driver_data *drv_data)
  106. {
  107. int rc = 0;
  108. /* get clk resource mgr ops */
  109. rc = mmrm_get_clk_mgr_ops(drv_data);
  110. if (rc) {
  111. d_mpr_e("%s: init clk mgr failed\n", __func__);
  112. goto err_get_clk_mgr_ops;
  113. }
  114. /* clock resource mgr */
  115. rc = drv_data->clk_mgr_ops->init_clk_mgr(drv_data);
  116. if (rc) {
  117. d_mpr_e("%s: init clk mgr failed\n", __func__);
  118. goto err_init_clk_mgr;
  119. }
  120. return rc;
  121. err_init_clk_mgr:
  122. err_get_clk_mgr_ops:
  123. return rc;
  124. }
  125. int mmrm_deinit(struct mmrm_driver_data *drv_data)
  126. {
  127. int rc = 0;
  128. if (!drv_data || !drv_data->clk_mgr_ops ||
  129. !drv_data->clk_mgr_ops->destroy_clk_mgr) {
  130. d_mpr_e("%s: invalid driver data or clk mgr ops\n", __func__);
  131. return -EINVAL;
  132. }
  133. /* destroy clock resource mgr */
  134. rc = drv_data->clk_mgr_ops->destroy_clk_mgr(drv_data->clk_mgr);
  135. if (rc) {
  136. d_mpr_e("%s: destroy clk mgr failed\n", __func__);
  137. drv_data->clk_mgr = NULL;
  138. }
  139. return rc;
  140. }