1 /*
2 * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022-2023 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
tgt_set_gpio_config_req(struct wlan_objmgr_psoc * psoc,struct gpio_config_params * param)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
tgt_set_gpio_output_req(struct wlan_objmgr_psoc * psoc,struct gpio_output_params * param)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
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 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(¶m, 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, ¶m);
83 }
84
85 qdf_export_symbol(tgt_gpio_config);
86
tgt_gpio_disabled(struct wlan_objmgr_psoc * psoc)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_QCN9160) ||
106 (target_type == TARGET_TYPE_QCA8074V2) ||
107 (target_type == TARGET_TYPE_QCA9574) ||
108 (target_type == TARGET_TYPE_QCA5332) ||
109 (target_type == TARGET_TYPE_QCN6432) ||
110 (target_type == TARGET_TYPE_QCA5018) ||
111 (target_type == TARGET_TYPE_QCA6018)) {
112 return true;
113 }
114
115 return false;
116 }
117
tgt_gpio_output(struct wlan_objmgr_psoc * psoc,uint32_t gpio_num,uint32_t set)118 QDF_STATUS tgt_gpio_output(struct wlan_objmgr_psoc *psoc, uint32_t gpio_num,
119 uint32_t set)
120 {
121 struct gpio_output_params param;
122
123 if (!psoc) {
124 gpio_err("psoc_obj is null");
125 return QDF_STATUS_E_INVAL;
126 }
127
128 if (tgt_gpio_disabled(psoc))
129 return QDF_STATUS_E_INVAL;
130
131 qdf_mem_set(¶m, sizeof(param), 0);
132 param.pin_num = gpio_num;
133 param.pin_set = set;
134
135 return tgt_set_gpio_output_req(psoc, ¶m);
136 }
137
138 qdf_export_symbol(tgt_gpio_output);
139