xref: /wlan-dirver/qca-wifi-host-cmn/gpio/dispatcher/src/wlan_gpio_tgt_api.c (revision 8b3dca18206e1a0461492f082fa6e270b092c035)
1 /*
2  * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 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 /**
19  * DOC:wlan_gpio_tgt_api.c
20  *
21  * This file provide API definitions to update gpio configuration from interface
22  */
23 #include <wlan_gpio_priv_api.h>
24 #include <wlan_gpio_tgt_api.h>
25 #include <target_type.h>
26 #include <qdf_module.h>
27 
28 QDF_STATUS tgt_set_gpio_config_req(struct wlan_objmgr_psoc *psoc,
29 				   struct gpio_config_params *param)
30 {
31 	struct wlan_lmac_if_gpio_tx_ops *gpio_tx_ops;
32 
33 	if (!psoc) {
34 		gpio_err("NULL psoc");
35 		return QDF_STATUS_E_NULL_VALUE;
36 	}
37 	gpio_tx_ops = wlan_psoc_get_gpio_txops(psoc);
38 	if (!gpio_tx_ops)
39 		return QDF_STATUS_E_NULL_VALUE;
40 
41 	return gpio_tx_ops->set_gpio_config(psoc, param);
42 }
43 
44 QDF_STATUS tgt_set_gpio_output_req(struct wlan_objmgr_psoc *psoc,
45 				   struct gpio_output_params *param)
46 {
47 	struct wlan_lmac_if_gpio_tx_ops *gpio_tx_ops;
48 
49 	if (!psoc) {
50 		gpio_err("NULL psoc");
51 		return QDF_STATUS_E_NULL_VALUE;
52 	}
53 
54 	gpio_tx_ops = wlan_psoc_get_gpio_txops(psoc);
55 	if (!gpio_tx_ops)
56 		return QDF_STATUS_E_NULL_VALUE;
57 
58 	return gpio_tx_ops->set_gpio_output(psoc, param);
59 }
60 
61 QDF_STATUS tgt_gpio_config(struct wlan_objmgr_psoc *psoc, uint32_t gpio_num,
62 			   uint32_t input, uint32_t pull_type,
63 			   uint32_t intr_mode,  uint32_t mux_config_val,
64 			   uint32_t drive, uint32_t init_enable)
65 {
66 	struct gpio_config_params param;
67 
68 	if (!psoc) {
69 		gpio_err("psoc_obj is null");
70 		return QDF_STATUS_E_INVAL;
71 	}
72 
73 	qdf_mem_set(&param, sizeof(param), 0);
74 	param.pin_pull_type = pull_type;
75 	param.pin_num = gpio_num;
76 	param.pin_dir = input;
77 	param.pin_intr_mode = intr_mode;
78 	param.mux_config_val = mux_config_val;
79 	param.drive = drive;
80 	param.init_enable = init_enable;
81 
82 	return tgt_set_gpio_config_req(psoc, &param);
83 }
84 
85 qdf_export_symbol(tgt_gpio_config);
86 
87 static bool tgt_gpio_disabled(struct wlan_objmgr_psoc *psoc)
88 {
89 	uint32_t target_type = 0;
90 	struct wlan_lmac_if_target_tx_ops *target_type_tx_ops;
91 	struct wlan_lmac_if_tx_ops *tx_ops;
92 
93 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
94 	if (!tx_ops) {
95 		gpio_err("tx_ops is NULL");
96 		return false;
97 	}
98 	target_type_tx_ops = &tx_ops->target_tx_ops;
99 
100 	if (target_type_tx_ops->tgt_get_tgt_type)
101 		target_type = target_type_tx_ops->tgt_get_tgt_type(psoc);
102 
103 	if ((target_type == TARGET_TYPE_QCA8074) ||
104 	    (target_type == TARGET_TYPE_QCN6122) ||
105 	    (target_type == TARGET_TYPE_QCA8074V2) ||
106 	    (target_type == TARGET_TYPE_QCA9574) ||
107 	    (target_type == TARGET_TYPE_QCA5332) ||
108 	    (target_type == TARGET_TYPE_QCA5018) ||
109 	    (target_type == TARGET_TYPE_QCA6018)) {
110 		return true;
111 	}
112 
113 	return false;
114 }
115 
116 QDF_STATUS tgt_gpio_output(struct wlan_objmgr_psoc *psoc, uint32_t gpio_num,
117 			   uint32_t set)
118 {
119 	struct gpio_output_params param;
120 
121 	if (!psoc) {
122 		gpio_err("psoc_obj is null");
123 		return QDF_STATUS_E_INVAL;
124 	}
125 
126 	if (tgt_gpio_disabled(psoc))
127 		return QDF_STATUS_E_INVAL;
128 
129 	qdf_mem_set(&param, sizeof(param), 0);
130 	param.pin_num = gpio_num;
131 	param.pin_set = set;
132 
133 	return tgt_set_gpio_output_req(psoc, &param);
134 }
135 
136 qdf_export_symbol(tgt_gpio_output);
137