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