1 /* 2 * Copyright (c) 2020, The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 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 27 QDF_STATUS tgt_set_gpio_config_req(struct wlan_objmgr_psoc *psoc, 28 struct gpio_config_params *param) 29 { 30 struct wlan_lmac_if_gpio_tx_ops *gpio_tx_ops; 31 32 if (!psoc) { 33 gpio_err("NULL psoc"); 34 return QDF_STATUS_E_NULL_VALUE; 35 } 36 gpio_tx_ops = wlan_psoc_get_gpio_txops(psoc); 37 if (!gpio_tx_ops) 38 return QDF_STATUS_E_NULL_VALUE; 39 40 return gpio_tx_ops->set_gpio_config(psoc, param); 41 } 42 43 QDF_STATUS tgt_set_gpio_output_req(struct wlan_objmgr_psoc *psoc, 44 struct gpio_output_params *param) 45 { 46 struct wlan_lmac_if_gpio_tx_ops *gpio_tx_ops; 47 48 if (!psoc) { 49 gpio_err("NULL psoc"); 50 return QDF_STATUS_E_NULL_VALUE; 51 } 52 53 gpio_tx_ops = wlan_psoc_get_gpio_txops(psoc); 54 if (!gpio_tx_ops) 55 return QDF_STATUS_E_NULL_VALUE; 56 57 return gpio_tx_ops->set_gpio_output(psoc, param); 58 } 59 60 QDF_STATUS tgt_gpio_config(struct wlan_objmgr_psoc *psoc, uint32_t gpio_num, 61 uint32_t input, uint32_t pull_type, 62 uint32_t intr_mode, uint32_t mux_config_val, 63 uint32_t drive, uint32_t init_enable) 64 { 65 struct gpio_config_params param; 66 67 if (!psoc) { 68 gpio_err("psoc_obj is null"); 69 return QDF_STATUS_E_INVAL; 70 } 71 72 qdf_mem_set(¶m, sizeof(param), 0); 73 param.pin_pull_type = pull_type; 74 param.pin_num = gpio_num; 75 param.pin_dir = input; 76 param.pin_intr_mode = intr_mode; 77 param.mux_config_val = mux_config_val; 78 param.drive = drive; 79 param.init_enable = init_enable; 80 81 return tgt_set_gpio_config_req(psoc, ¶m); 82 } 83 84 qdf_export_symbol(tgt_gpio_config); 85 86 static bool tgt_gpio_disabled(struct wlan_objmgr_psoc *psoc) 87 { 88 uint32_t target_type = 0; 89 struct wlan_lmac_if_target_tx_ops *target_type_tx_ops; 90 struct wlan_lmac_if_tx_ops *tx_ops; 91 92 tx_ops = wlan_psoc_get_lmac_if_txops(psoc); 93 if (!tx_ops) { 94 gpio_err("tx_ops is NULL"); 95 return false; 96 } 97 target_type_tx_ops = &tx_ops->target_tx_ops; 98 99 if (target_type_tx_ops->tgt_get_tgt_type) 100 target_type = target_type_tx_ops->tgt_get_tgt_type(psoc); 101 102 if ((target_type == TARGET_TYPE_QCA8074) || 103 (target_type == TARGET_TYPE_QCN9100) || 104 (target_type == TARGET_TYPE_QCA8074V2) || 105 (target_type == TARGET_TYPE_QCA5018) || 106 (target_type == TARGET_TYPE_QCA6018)) { 107 return true; 108 } 109 110 return false; 111 } 112 113 QDF_STATUS tgt_gpio_output(struct wlan_objmgr_psoc *psoc, uint32_t gpio_num, 114 uint32_t set) 115 { 116 struct gpio_output_params param; 117 118 if (!psoc) { 119 gpio_err("psoc_obj is null"); 120 return QDF_STATUS_E_INVAL; 121 } 122 123 if (tgt_gpio_disabled(psoc)) 124 return QDF_STATUS_E_INVAL; 125 126 qdf_mem_set(¶m, sizeof(param), 0); 127 param.pin_num = gpio_num; 128 param.pin_set = set; 129 130 return tgt_set_gpio_output_req(psoc, ¶m); 131 } 132 133 qdf_export_symbol(tgt_gpio_output); 134