wlan_gpio_tgt_api.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /**
  18. * DOC:wlan_gpio_tgt_api.c
  19. *
  20. * This file provide API definitions to update gpio configuration from interface
  21. */
  22. #include <wlan_gpio_priv_api.h>
  23. #include <wlan_gpio_tgt_api.h>
  24. #include <target_type.h>
  25. #include <qdf_module.h>
  26. QDF_STATUS tgt_set_gpio_config_req(struct wlan_objmgr_psoc *psoc,
  27. struct gpio_config_params *param)
  28. {
  29. struct wlan_lmac_if_gpio_tx_ops *gpio_tx_ops;
  30. if (!psoc) {
  31. gpio_err("NULL psoc");
  32. return QDF_STATUS_E_NULL_VALUE;
  33. }
  34. gpio_tx_ops = wlan_psoc_get_gpio_txops(psoc);
  35. if (!gpio_tx_ops)
  36. return QDF_STATUS_E_NULL_VALUE;
  37. return gpio_tx_ops->set_gpio_config(psoc, param);
  38. }
  39. QDF_STATUS tgt_set_gpio_output_req(struct wlan_objmgr_psoc *psoc,
  40. struct gpio_output_params *param)
  41. {
  42. struct wlan_lmac_if_gpio_tx_ops *gpio_tx_ops;
  43. if (!psoc) {
  44. gpio_err("NULL psoc");
  45. return QDF_STATUS_E_NULL_VALUE;
  46. }
  47. gpio_tx_ops = wlan_psoc_get_gpio_txops(psoc);
  48. if (!gpio_tx_ops)
  49. return QDF_STATUS_E_NULL_VALUE;
  50. return gpio_tx_ops->set_gpio_output(psoc, param);
  51. }
  52. QDF_STATUS tgt_gpio_config(struct wlan_objmgr_psoc *psoc, uint32_t gpio_num,
  53. uint32_t input, uint32_t pull_type,
  54. uint32_t intr_mode, uint32_t mux_config_val,
  55. uint32_t drive, uint32_t init_enable)
  56. {
  57. struct gpio_config_params param;
  58. if (!psoc) {
  59. gpio_err("psoc_obj is null");
  60. return QDF_STATUS_E_INVAL;
  61. }
  62. qdf_mem_set(&param, sizeof(param), 0);
  63. param.pin_pull_type = pull_type;
  64. param.pin_num = gpio_num;
  65. param.pin_dir = input;
  66. param.pin_intr_mode = intr_mode;
  67. param.mux_config_val = mux_config_val;
  68. param.drive = drive;
  69. param.init_enable = init_enable;
  70. return tgt_set_gpio_config_req(psoc, &param);
  71. }
  72. qdf_export_symbol(tgt_gpio_config);
  73. static bool tgt_gpio_disabled(struct wlan_objmgr_psoc *psoc)
  74. {
  75. uint32_t target_type = 0;
  76. struct wlan_lmac_if_target_tx_ops *target_type_tx_ops;
  77. struct wlan_lmac_if_tx_ops *tx_ops;
  78. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  79. if (!tx_ops) {
  80. gpio_err("tx_ops is NULL");
  81. return false;
  82. }
  83. target_type_tx_ops = &tx_ops->target_tx_ops;
  84. if (target_type_tx_ops->tgt_get_tgt_type)
  85. target_type = target_type_tx_ops->tgt_get_tgt_type(psoc);
  86. if ((target_type == TARGET_TYPE_QCA8074) ||
  87. (target_type == TARGET_TYPE_QCN6122) ||
  88. (target_type == TARGET_TYPE_QCN9160) ||
  89. (target_type == TARGET_TYPE_QCA8074V2) ||
  90. (target_type == TARGET_TYPE_QCA9574) ||
  91. (target_type == TARGET_TYPE_QCA5332) ||
  92. (target_type == TARGET_TYPE_QCN6432) ||
  93. (target_type == TARGET_TYPE_QCA5018) ||
  94. (target_type == TARGET_TYPE_QCA6018)) {
  95. return true;
  96. }
  97. return false;
  98. }
  99. QDF_STATUS tgt_gpio_output(struct wlan_objmgr_psoc *psoc, uint32_t gpio_num,
  100. uint32_t set)
  101. {
  102. struct gpio_output_params param;
  103. if (!psoc) {
  104. gpio_err("psoc_obj is null");
  105. return QDF_STATUS_E_INVAL;
  106. }
  107. if (tgt_gpio_disabled(psoc))
  108. return QDF_STATUS_E_INVAL;
  109. qdf_mem_set(&param, sizeof(param), 0);
  110. param.pin_num = gpio_num;
  111. param.pin_set = set;
  112. return tgt_set_gpio_output_req(psoc, &param);
  113. }
  114. qdf_export_symbol(tgt_gpio_output);