xref: /wlan-dirver/qca-wifi-host-cmn/gpio/dispatcher/src/wlan_gpio_tgt_api.c (revision 8e8ac2c5d106253d117a432e0e7a967653f9e94e)
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)
63 {
64 	struct gpio_config_params param;
65 
66 	if (!psoc) {
67 		gpio_err("psoc_obj is null");
68 		return QDF_STATUS_E_INVAL;
69 	}
70 
71 	qdf_mem_set(&param, sizeof(param), 0);
72 	param.pin_pull_type = pull_type;
73 	param.pin_num = gpio_num;
74 	param.pin_dir = input;
75 	param.pin_intr_mode = intr_mode;
76 
77 	return tgt_set_gpio_config_req(psoc, &param);
78 }
79 
80 qdf_export_symbol(tgt_gpio_config);
81 
82 static bool tgt_gpio_disabled(struct wlan_objmgr_psoc *psoc)
83 {
84 	uint32_t target_type = 0;
85 	struct wlan_lmac_if_target_tx_ops *target_type_tx_ops;
86 	struct wlan_lmac_if_tx_ops *tx_ops;
87 
88 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
89 	if (!tx_ops) {
90 		gpio_err("tx_ops is NULL");
91 		return false;
92 	}
93 	target_type_tx_ops = &tx_ops->target_tx_ops;
94 
95 	if (target_type_tx_ops->tgt_get_tgt_type)
96 		target_type = target_type_tx_ops->tgt_get_tgt_type(psoc);
97 
98 	if ((target_type == TARGET_TYPE_QCA8074) ||
99 	    (target_type == TARGET_TYPE_QCN9100) ||
100 	    (target_type == TARGET_TYPE_QCA8074V2) ||
101 	    (target_type == TARGET_TYPE_QCA5018) ||
102 	    (target_type == TARGET_TYPE_QCA6018)) {
103 		return true;
104 	}
105 
106 	return false;
107 }
108 
109 QDF_STATUS tgt_gpio_output(struct wlan_objmgr_psoc *psoc, uint32_t gpio_num,
110 			   uint32_t set)
111 {
112 	struct gpio_output_params param;
113 
114 	if (!psoc) {
115 		gpio_err("psoc_obj is null");
116 		return QDF_STATUS_E_INVAL;
117 	}
118 
119 	if (tgt_gpio_disabled(psoc))
120 		return QDF_STATUS_E_INVAL;
121 
122 	qdf_mem_set(&param, sizeof(param), 0);
123 	param.pin_num = gpio_num;
124 	param.pin_set = set;
125 
126 	return tgt_set_gpio_output_req(psoc, &param);
127 }
128 
129 qdf_export_symbol(tgt_gpio_output);
130