hc
2024-05-08 f309769f8af08599af39b6de4f675784ce76530d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/******************************************************************************
 *
 * Copyright(c) 2016 - 2019 Realtek Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 ******************************************************************************/
 
#include "halmac_gpio_88xx.h"
 
#if HALMAC_88XX_SUPPORT
 
/**
 * pinmux_wl_led_mode_88xx() -control wlan led gpio function
 * @adapter : the adapter of halmac
 * @mode : wlan led mode
 * Author : Ivan Lin
 * Return : enum halmac_ret_status
 * More details of status code can be found in prototype document
 */
enum halmac_ret_status
pinmux_wl_led_mode_88xx(struct halmac_adapter *adapter,
           enum halmac_wlled_mode mode)
{
   u8 value8;
   struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
 
   PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
 
   value8 = HALMAC_REG_R8(REG_LED_CFG + 2);
   value8 &= ~(BIT(6));
   value8 |= BIT(3);
   value8 &= ~(BIT(0) | BIT(1) | BIT(2));
 
   switch (mode) {
   case HALMAC_WLLED_MODE_TRX:
       value8 |= 2;
       break;
   case HALMAC_WLLED_MODE_TX:
       value8 |= 4;
       break;
   case HALMAC_WLLED_MODE_RX:
       value8 |= 6;
       break;
   case HALMAC_WLLED_MODE_SW_CTRL:
       value8 |= 0;
       break;
   default:
       return HALMAC_RET_SWITCH_CASE_ERROR;
   }
 
   HALMAC_REG_W8(REG_LED_CFG + 2, value8);
 
   PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
 
   return HALMAC_RET_SUCCESS;
}
 
/**
 * pinmux_wl_led_sw_ctrl_88xx() -control wlan led on/off
 * @adapter : the adapter of halmac
 * @on : on(1), off(0)
 * Author : Ivan Lin
 * Return : enum halmac_ret_status
 * More details of status code can be found in prototype document
 */
void
pinmux_wl_led_sw_ctrl_88xx(struct halmac_adapter *adapter, u8 on)
{
   u8 value8;
   struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
 
   value8 = HALMAC_REG_R8(REG_LED_CFG + 2);
   value8 = (on == 0) ? value8 | BIT(3) : value8 & ~(BIT(3));
 
   HALMAC_REG_W8(REG_LED_CFG + 2, value8);
}
 
/**
 * pinmux_sdio_int_polarity_88xx() -control sdio int polarity
 * @adapter : the adapter of halmac
 * @low_active : low active(1), high active(0)
 * Author : Ivan Lin
 * Return : enum halmac_ret_status
 * More details of status code can be found in prototype document
 */
void
pinmux_sdio_int_polarity_88xx(struct halmac_adapter *adapter, u8 low_active)
{
   u8 value8;
   struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
 
   value8 = HALMAC_REG_R8(REG_SYS_SDIO_CTRL + 2);
   value8 = (low_active == 0) ? value8 | BIT(3) : value8 & ~(BIT(3));
 
   HALMAC_REG_W8(REG_SYS_SDIO_CTRL + 2, value8);
}
 
/**
 * pinmux_gpio_mode_88xx() -control gpio io mode
 * @adapter : the adapter of halmac
 * @gpio_id : gpio0~15(0~15)
 * @output : output(1), input(0)
 * Author : Ivan Lin
 * Return : enum halmac_ret_status
 * More details of status code can be found in prototype document
 */
enum halmac_ret_status
pinmux_gpio_mode_88xx(struct halmac_adapter *adapter, u8 gpio_id, u8 output)
{
   u16 value16;
   u8 in_out;
   u32 offset;
   struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
 
   if (gpio_id <= 7)
       offset = REG_GPIO_PIN_CTRL + 2;
   else if (gpio_id >= 8 && gpio_id <= 15)
       offset = REG_GPIO_EXT_CTRL + 2;
   else
       return HALMAC_RET_WRONG_GPIO;
 
   in_out = (output == 0) ? 0 : 1;
   gpio_id &= (8 - 1);
 
   value16 = HALMAC_REG_R16(offset);
   value16 &= ~((1 << gpio_id) | (1 << gpio_id << 8));
   value16 |= (in_out << gpio_id);
   HALMAC_REG_W16(offset, value16);
 
   return HALMAC_RET_SUCCESS;
}
 
/**
 * pinmux_gpio_output_88xx() -control gpio output high/low
 * @adapter : the adapter of halmac
 * @gpio_id : gpio0~15(0~15)
 * @high : high(1), low(0)
 * Author : Ivan Lin
 * Return : enum halmac_ret_status
 * More details of status code can be found in prototype document
 */
enum halmac_ret_status
pinmux_gpio_output_88xx(struct halmac_adapter *adapter, u8 gpio_id, u8 high)
{
   u8 value8;
   u8 hi_low;
   u32 offset;
   struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
 
   if (gpio_id <= 7)
       offset = REG_GPIO_PIN_CTRL + 1;
   else if (gpio_id >= 8 && gpio_id <= 15)
       offset = REG_GPIO_EXT_CTRL + 1;
   else
       return HALMAC_RET_WRONG_GPIO;
 
   hi_low = (high == 0) ? 0 : 1;
   gpio_id &= (8 - 1);
 
   value8 = HALMAC_REG_R8(offset);
   value8 &= ~(1 << gpio_id);
   value8 |= (hi_low << gpio_id);
   HALMAC_REG_W8(offset, value8);
 
   return HALMAC_RET_SUCCESS;
}
 
/**
 * halmac_pinmux_status_88xx() -get current gpio status(high/low)
 * @adapter : the adapter of halmac
 * @pin_id : 0~15(0~15)
 * @phigh : high(1), low(0)
 * Author : Ivan Lin
 * Return : enum halmac_ret_status
 * More details of status code can be found in prototype document
 */
enum halmac_ret_status
pinmux_pin_status_88xx(struct halmac_adapter *adapter, u8 pin_id, u8 *high)
{
   u8 value8;
   u32 offset;
   struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
 
   if (pin_id <= 7)
       offset = REG_GPIO_PIN_CTRL;
   else if (pin_id >= 8 && pin_id <= 15)
       offset = REG_GPIO_EXT_CTRL;
   else
       return HALMAC_RET_WRONG_GPIO;
 
   pin_id &= (8 - 1);
 
   value8 = HALMAC_REG_R8(offset);
   *high = (value8 & (1 << pin_id)) >> pin_id;
 
   return HALMAC_RET_SUCCESS;
}
 
enum halmac_ret_status
pinmux_parser_88xx(struct halmac_adapter *adapter,
          const struct halmac_gpio_pimux_list *list, u32 size,
          u32 gpio_id, u32 *cur_func)
{
   u32 i;
   u8 value8;
   const struct halmac_gpio_pimux_list *cur_list = list;
   enum halmac_gpio_cfg_state *state;
   struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
 
   state = &adapter->halmac_state.gpio_cfg_state;
 
   if (*state == HALMAC_GPIO_CFG_STATE_BUSY)
       return HALMAC_RET_BUSY_STATE;
 
   *state = HALMAC_GPIO_CFG_STATE_BUSY;
 
   for (i = 0; i < size; i++) {
       if (gpio_id != cur_list->id) {
           PLTFM_MSG_ERR("[ERR]offset:%X, value:%X, func:%X\n",
                     cur_list->offset, cur_list->value,
                     cur_list->func);
           PLTFM_MSG_ERR("[ERR]id1 : %X, id2 : %X\n",
                     gpio_id, cur_list->id);
           *state = HALMAC_GPIO_CFG_STATE_IDLE;
           return HALMAC_RET_GET_PINMUX_ERR;
       }
       value8 = HALMAC_REG_R8(cur_list->offset);
       value8 &= cur_list->msk;
       if (value8 == cur_list->value) {
           *cur_func = cur_list->func;
           break;
       }
       cur_list++;
   }
 
   switch (*cur_func) {
   case HALMAC_BT_DPDT_SEL:
       *cur_func = (HALMAC_REG_R8(REG_LED_CFG + 3) & BIT(0)) ?
               HALMAC_WL_DPDT_SEL : HALMAC_BT_DPDT_SEL;
       break;
   case HALMAC_BT_PAPE_SEL:
       *cur_func = (HALMAC_REG_R8(REG_PAD_CTRL1 + 3) & BIT(5)) ?
               HALMAC_WL_PAPE_SEL : HALMAC_BT_PAPE_SEL;
       break;
   case HALMAC_BT_LNAON_SEL:
       *cur_func = (HALMAC_REG_R8(REG_PAD_CTRL1 + 3) & BIT(4)) ?
               HALMAC_WL_LNAON_SEL : HALMAC_BT_LNAON_SEL;
       break;
   default:
       break;
   }
 
   *state = HALMAC_GPIO_CFG_STATE_IDLE;
 
   if (i == size)
       return HALMAC_RET_GET_PINMUX_ERR;
 
   return HALMAC_RET_SUCCESS;
}
 
#endif /* HALMAC_88XX_SUPPORT */