xref: /wlan-dirver/qca-wifi-host-cmn/gpio/dispatcher/src/wlan_gpio_tgt_api.c (revision 2f4b444fb7e689b83a4ab0e7b3b38f0bf4def8e0)
1 /*
2  * Copyright (c) 2020-2021, 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(&param, 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, &param);
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_QCN6122) ||
104 	    (target_type == TARGET_TYPE_QCA8074V2) ||
105 	    (target_type == TARGET_TYPE_QCA9574) ||
106 	    (target_type == TARGET_TYPE_QCA5018) ||
107 	    (target_type == TARGET_TYPE_QCA6018)) {
108 		return true;
109 	}
110 
111 	return false;
112 }
113 
114 QDF_STATUS tgt_gpio_output(struct wlan_objmgr_psoc *psoc, uint32_t gpio_num,
115 			   uint32_t set)
116 {
117 	struct gpio_output_params param;
118 
119 	if (!psoc) {
120 		gpio_err("psoc_obj is null");
121 		return QDF_STATUS_E_INVAL;
122 	}
123 
124 	if (tgt_gpio_disabled(psoc))
125 		return QDF_STATUS_E_INVAL;
126 
127 	qdf_mem_set(&param, sizeof(param), 0);
128 	param.pin_num = gpio_num;
129 	param.pin_set = set;
130 
131 	return tgt_set_gpio_output_req(psoc, &param);
132 }
133 
134 qdf_export_symbol(tgt_gpio_output);
135