1 /******************************************************************************
3 * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
16 #include "halmac_gpio_88xx.h"
18 #if HALMAC_88XX_SUPPORT
21 * pinmux_wl_led_mode_88xx() -control wlan led gpio function
22 * @adapter : the adapter of halmac
23 * @mode : wlan led mode
25 * Return : enum halmac_ret_status
26 * More details of status code can be found in prototype document
28 enum halmac_ret_status
29 pinmux_wl_led_mode_88xx(struct halmac_adapter *adapter,
30 enum halmac_wlled_mode mode)
33 struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
35 PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
37 value8 = HALMAC_REG_R8(REG_LED_CFG + 2);
40 value8 &= ~(BIT(0) | BIT(1) | BIT(2));
43 case HALMAC_WLLED_MODE_TRX:
46 case HALMAC_WLLED_MODE_TX:
49 case HALMAC_WLLED_MODE_RX:
52 case HALMAC_WLLED_MODE_SW_CTRL:
56 return HALMAC_RET_SWITCH_CASE_ERROR;
59 HALMAC_REG_W8(REG_LED_CFG + 2, value8);
61 PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
63 return HALMAC_RET_SUCCESS;
67 * pinmux_wl_led_sw_ctrl_88xx() -control wlan led on/off
68 * @adapter : the adapter of halmac
71 * Return : enum halmac_ret_status
72 * More details of status code can be found in prototype document
75 pinmux_wl_led_sw_ctrl_88xx(struct halmac_adapter *adapter, u8 on)
78 struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
80 value8 = HALMAC_REG_R8(REG_LED_CFG + 2);
81 value8 = (on == 0) ? value8 | BIT(3) : value8 & ~(BIT(3));
83 HALMAC_REG_W8(REG_LED_CFG + 2, value8);
87 * pinmux_sdio_int_polarity_88xx() -control sdio int polarity
88 * @adapter : the adapter of halmac
89 * @low_active : low active(1), high active(0)
91 * Return : enum halmac_ret_status
92 * More details of status code can be found in prototype document
95 pinmux_sdio_int_polarity_88xx(struct halmac_adapter *adapter, u8 low_active)
98 struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
100 value8 = HALMAC_REG_R8(REG_SYS_SDIO_CTRL + 2);
101 value8 = (low_active == 0) ? value8 | BIT(3) : value8 & ~(BIT(3));
103 HALMAC_REG_W8(REG_SYS_SDIO_CTRL + 2, value8);
107 * pinmux_gpio_mode_88xx() -control gpio io mode
108 * @adapter : the adapter of halmac
109 * @gpio_id : gpio0~15(0~15)
110 * @output : output(1), input(0)
112 * Return : enum halmac_ret_status
113 * More details of status code can be found in prototype document
115 enum halmac_ret_status
116 pinmux_gpio_mode_88xx(struct halmac_adapter *adapter, u8 gpio_id, u8 output)
121 struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
124 offset = REG_GPIO_PIN_CTRL + 2;
125 else if (gpio_id >= 8 && gpio_id <= 15)
126 offset = REG_GPIO_EXT_CTRL + 2;
128 return HALMAC_RET_WRONG_GPIO;
130 in_out = (output == 0) ? 0 : 1;
133 value16 = HALMAC_REG_R16(offset);
134 value16 &= ~((1 << gpio_id) | (1 << gpio_id << 8));
135 value16 |= (in_out << gpio_id);
136 HALMAC_REG_W16(offset, value16);
138 return HALMAC_RET_SUCCESS;
142 * pinmux_gpio_output_88xx() -control gpio output high/low
143 * @adapter : the adapter of halmac
144 * @gpio_id : gpio0~15(0~15)
145 * @high : high(1), low(0)
147 * Return : enum halmac_ret_status
148 * More details of status code can be found in prototype document
150 enum halmac_ret_status
151 pinmux_gpio_output_88xx(struct halmac_adapter *adapter, u8 gpio_id, u8 high)
156 struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
159 offset = REG_GPIO_PIN_CTRL + 1;
160 else if (gpio_id >= 8 && gpio_id <= 15)
161 offset = REG_GPIO_EXT_CTRL + 1;
163 return HALMAC_RET_WRONG_GPIO;
165 hi_low = (high == 0) ? 0 : 1;
168 value8 = HALMAC_REG_R8(offset);
169 value8 &= ~(1 << gpio_id);
170 value8 |= (hi_low << gpio_id);
171 HALMAC_REG_W8(offset, value8);
173 return HALMAC_RET_SUCCESS;
177 * halmac_pinmux_status_88xx() -get current gpio status(high/low)
178 * @adapter : the adapter of halmac
179 * @pin_id : 0~15(0~15)
180 * @phigh : high(1), low(0)
182 * Return : enum halmac_ret_status
183 * More details of status code can be found in prototype document
185 enum halmac_ret_status
186 pinmux_pin_status_88xx(struct halmac_adapter *adapter, u8 pin_id, u8 *high)
190 struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
193 offset = REG_GPIO_PIN_CTRL;
194 else if (pin_id >= 8 && pin_id <= 15)
195 offset = REG_GPIO_EXT_CTRL;
197 return HALMAC_RET_WRONG_GPIO;
201 value8 = HALMAC_REG_R8(offset);
202 *high = (value8 & (1 << pin_id)) >> pin_id;
204 return HALMAC_RET_SUCCESS;
207 enum halmac_ret_status
208 pinmux_parser_88xx(struct halmac_adapter *adapter,
209 const struct halmac_gpio_pimux_list *list, u32 size,
210 u32 gpio_id, u32 *cur_func)
214 const struct halmac_gpio_pimux_list *cur_list = list;
215 enum halmac_gpio_cfg_state *state;
216 struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
218 state = &adapter->halmac_state.gpio_cfg_state;
220 if (*state == HALMAC_GPIO_CFG_STATE_BUSY)
221 return HALMAC_RET_BUSY_STATE;
223 *state = HALMAC_GPIO_CFG_STATE_BUSY;
225 for (i = 0; i < size; i++) {
226 if (gpio_id != cur_list->id) {
227 PLTFM_MSG_ERR("[ERR]offset:%X, value:%X, func:%X\n",
228 cur_list->offset, cur_list->value,
230 PLTFM_MSG_ERR("[ERR]id1 : %X, id2 : %X\n",
231 gpio_id, cur_list->id);
232 *state = HALMAC_GPIO_CFG_STATE_IDLE;
233 return HALMAC_RET_GET_PINMUX_ERR;
235 value8 = HALMAC_REG_R8(cur_list->offset);
236 value8 &= cur_list->msk;
237 if (value8 == cur_list->value) {
238 *cur_func = cur_list->func;
244 *state = HALMAC_GPIO_CFG_STATE_IDLE;
247 return HALMAC_RET_GET_PINMUX_ERR;
249 return HALMAC_RET_SUCCESS;
252 enum halmac_ret_status
253 pinmux_switch_88xx(struct halmac_adapter *adapter,
254 const struct halmac_gpio_pimux_list *list, u32 size,
255 u32 gpio_id, enum halmac_gpio_func gpio_func)
260 const struct halmac_gpio_pimux_list *cur_list = list;
261 enum halmac_gpio_cfg_state *state;
262 struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
264 state = &adapter->halmac_state.gpio_cfg_state;
266 if (*state == HALMAC_GPIO_CFG_STATE_BUSY)
267 return HALMAC_RET_BUSY_STATE;
270 case HALMAC_GPIO_FUNC_WL_LED:
271 switch_func = HALMAC_WL_LED;
273 case HALMAC_GPIO_FUNC_SDIO_INT:
274 switch_func = HALMAC_SDIO_INT;
276 case HALMAC_GPIO_FUNC_BT_HOST_WAKE1:
277 case HALMAC_GPIO_FUNC_BT_DEV_WAKE1:
278 switch_func = HALMAC_GPIO13_14_WL_CTRL_EN;
280 case HALMAC_GPIO_FUNC_SW_IO_0:
281 case HALMAC_GPIO_FUNC_SW_IO_1:
282 case HALMAC_GPIO_FUNC_SW_IO_2:
283 case HALMAC_GPIO_FUNC_SW_IO_3:
284 case HALMAC_GPIO_FUNC_SW_IO_4:
285 case HALMAC_GPIO_FUNC_SW_IO_5:
286 case HALMAC_GPIO_FUNC_SW_IO_6:
287 case HALMAC_GPIO_FUNC_SW_IO_7:
288 case HALMAC_GPIO_FUNC_SW_IO_8:
289 case HALMAC_GPIO_FUNC_SW_IO_9:
290 case HALMAC_GPIO_FUNC_SW_IO_10:
291 case HALMAC_GPIO_FUNC_SW_IO_11:
292 case HALMAC_GPIO_FUNC_SW_IO_12:
293 case HALMAC_GPIO_FUNC_SW_IO_13:
294 case HALMAC_GPIO_FUNC_SW_IO_14:
295 case HALMAC_GPIO_FUNC_SW_IO_15:
296 switch_func = HALMAC_SW_IO;
299 return HALMAC_RET_SWITCH_CASE_ERROR;
302 for (i = 0; i < size; i++) {
303 if (gpio_id != cur_list->id) {
304 PLTFM_MSG_ERR("[ERR]offset:%X, value:%X, func:%X\n",
305 cur_list->offset, cur_list->value,
307 PLTFM_MSG_ERR("[ERR]id1 : %X, id2 : %X\n",
308 gpio_id, cur_list->id);
309 return HALMAC_RET_GET_PINMUX_ERR;
312 if (switch_func == cur_list->func)
319 PLTFM_MSG_ERR("[ERR]gpio func error:%X %X\n",
320 gpio_id, cur_list->id);
321 return HALMAC_RET_GET_PINMUX_ERR;
324 *state = HALMAC_GPIO_CFG_STATE_BUSY;
327 for (i = 0; i < size; i++) {
328 value8 = HALMAC_REG_R8(cur_list->offset);
329 value8 &= ~(cur_list->msk);
331 if (switch_func == cur_list->func) {
332 value8 |= (cur_list->value & cur_list->msk);
333 HALMAC_REG_W8(cur_list->offset, value8);
337 value8 |= (~cur_list->value & cur_list->msk);
338 HALMAC_REG_W8(cur_list->offset, value8);
343 *state = HALMAC_GPIO_CFG_STATE_IDLE;
345 return HALMAC_RET_SUCCESS;
348 enum halmac_ret_status
349 pinmux_record_88xx(struct halmac_adapter *adapter,
350 enum halmac_gpio_func gpio_func, u8 val)
353 case HALMAC_GPIO_FUNC_WL_LED:
354 adapter->pinmux_info.wl_led = val;
356 case HALMAC_GPIO_FUNC_SDIO_INT:
357 adapter->pinmux_info.sdio_int = val;
359 case HALMAC_GPIO_FUNC_BT_HOST_WAKE1:
360 adapter->pinmux_info.bt_host_wake = val;
362 case HALMAC_GPIO_FUNC_BT_DEV_WAKE1:
363 adapter->pinmux_info.bt_dev_wake = val;
365 case HALMAC_GPIO_FUNC_SW_IO_0:
366 adapter->pinmux_info.sw_io_0 = val;
368 case HALMAC_GPIO_FUNC_SW_IO_1:
369 adapter->pinmux_info.sw_io_1 = val;
371 case HALMAC_GPIO_FUNC_SW_IO_2:
372 adapter->pinmux_info.sw_io_2 = val;
374 case HALMAC_GPIO_FUNC_SW_IO_3:
375 adapter->pinmux_info.sw_io_3 = val;
377 case HALMAC_GPIO_FUNC_SW_IO_4:
378 adapter->pinmux_info.sw_io_4 = val;
380 case HALMAC_GPIO_FUNC_SW_IO_5:
381 adapter->pinmux_info.sw_io_5 = val;
383 case HALMAC_GPIO_FUNC_SW_IO_6:
384 adapter->pinmux_info.sw_io_6 = val;
386 case HALMAC_GPIO_FUNC_SW_IO_7:
387 adapter->pinmux_info.sw_io_7 = val;
389 case HALMAC_GPIO_FUNC_SW_IO_8:
390 adapter->pinmux_info.sw_io_8 = val;
392 case HALMAC_GPIO_FUNC_SW_IO_9:
393 adapter->pinmux_info.sw_io_9 = val;
395 case HALMAC_GPIO_FUNC_SW_IO_10:
396 adapter->pinmux_info.sw_io_10 = val;
398 case HALMAC_GPIO_FUNC_SW_IO_11:
399 adapter->pinmux_info.sw_io_11 = val;
401 case HALMAC_GPIO_FUNC_SW_IO_12:
402 adapter->pinmux_info.sw_io_12 = val;
404 case HALMAC_GPIO_FUNC_SW_IO_13:
405 adapter->pinmux_info.sw_io_13 = val;
407 case HALMAC_GPIO_FUNC_SW_IO_14:
408 adapter->pinmux_info.sw_io_14 = val;
410 case HALMAC_GPIO_FUNC_SW_IO_15:
411 adapter->pinmux_info.sw_io_15 = val;
414 return HALMAC_RET_GET_PINMUX_ERR;
417 return HALMAC_RET_SUCCESS;
420 #endif /* HALMAC_88XX_SUPPORT */