• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright(c) 2016 - 2019 Realtek Corporation. All rights reserved.
4  *
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.
8  *
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
12  * more details.
13  *
14  ******************************************************************************/
15 
16 #include "halmac_gpio_88xx.h"
17 
18 #if HALMAC_88XX_SUPPORT
19 
20 /**
21  * pinmux_wl_led_mode_88xx() -control wlan led gpio function
22  * @adapter : the adapter of halmac
23  * @mode : wlan led mode
24  * Author : Ivan Lin
25  * Return : enum halmac_ret_status
26  * More details of status code can be found in prototype document
27  */
28 enum halmac_ret_status
pinmux_wl_led_mode_88xx(struct halmac_adapter * adapter,enum halmac_wlled_mode mode)29 pinmux_wl_led_mode_88xx(struct halmac_adapter *adapter,
30 			enum halmac_wlled_mode mode)
31 {
32 	u8 value8;
33 	struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
34 
35 	PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
36 
37 	value8 = HALMAC_REG_R8(REG_LED_CFG + 2);
38 	value8 &= ~(BIT(6));
39 	value8 |= BIT(3);
40 	value8 &= ~(BIT(0) | BIT(1) | BIT(2));
41 
42 	switch (mode) {
43 	case HALMAC_WLLED_MODE_TRX:
44 		value8 |= 2;
45 		break;
46 	case HALMAC_WLLED_MODE_TX:
47 		value8 |= 4;
48 		break;
49 	case HALMAC_WLLED_MODE_RX:
50 		value8 |= 6;
51 		break;
52 	case HALMAC_WLLED_MODE_SW_CTRL:
53 		value8 |= 0;
54 		break;
55 	default:
56 		return HALMAC_RET_SWITCH_CASE_ERROR;
57 	}
58 
59 	HALMAC_REG_W8(REG_LED_CFG + 2, value8);
60 
61 	PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
62 
63 	return HALMAC_RET_SUCCESS;
64 }
65 
66 /**
67  * pinmux_wl_led_sw_ctrl_88xx() -control wlan led on/off
68  * @adapter : the adapter of halmac
69  * @on : on(1), off(0)
70  * Author : Ivan Lin
71  * Return : enum halmac_ret_status
72  * More details of status code can be found in prototype document
73  */
74 void
pinmux_wl_led_sw_ctrl_88xx(struct halmac_adapter * adapter,u8 on)75 pinmux_wl_led_sw_ctrl_88xx(struct halmac_adapter *adapter, u8 on)
76 {
77 	u8 value8;
78 	struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
79 
80 	value8 = HALMAC_REG_R8(REG_LED_CFG + 2);
81 	value8 = (on == 0) ? value8 | BIT(3) : value8 & ~(BIT(3));
82 
83 	HALMAC_REG_W8(REG_LED_CFG + 2, value8);
84 }
85 
86 /**
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)
90  * Author : Ivan Lin
91  * Return : enum halmac_ret_status
92  * More details of status code can be found in prototype document
93  */
94 void
pinmux_sdio_int_polarity_88xx(struct halmac_adapter * adapter,u8 low_active)95 pinmux_sdio_int_polarity_88xx(struct halmac_adapter *adapter, u8 low_active)
96 {
97 	u8 value8;
98 	struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
99 
100 	value8 = HALMAC_REG_R8(REG_SYS_SDIO_CTRL + 2);
101 	value8 = (low_active == 0) ? value8 | BIT(3) : value8 & ~(BIT(3));
102 
103 	HALMAC_REG_W8(REG_SYS_SDIO_CTRL + 2, value8);
104 }
105 
106 /**
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)
111  * Author : Ivan Lin
112  * Return : enum halmac_ret_status
113  * More details of status code can be found in prototype document
114  */
115 enum halmac_ret_status
pinmux_gpio_mode_88xx(struct halmac_adapter * adapter,u8 gpio_id,u8 output)116 pinmux_gpio_mode_88xx(struct halmac_adapter *adapter, u8 gpio_id, u8 output)
117 {
118 	u16 value16;
119 	u8 in_out;
120 	u32 offset;
121 	struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
122 
123 	if (gpio_id <= 7)
124 		offset = REG_GPIO_PIN_CTRL + 2;
125 	else if (gpio_id >= 8 && gpio_id <= 15)
126 		offset = REG_GPIO_EXT_CTRL + 2;
127 	else
128 		return HALMAC_RET_WRONG_GPIO;
129 
130 	in_out = (output == 0) ? 0 : 1;
131 	gpio_id &= (8 - 1);
132 
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);
137 
138 	return HALMAC_RET_SUCCESS;
139 }
140 
141 /**
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)
146  * Author : Ivan Lin
147  * Return : enum halmac_ret_status
148  * More details of status code can be found in prototype document
149  */
150 enum halmac_ret_status
pinmux_gpio_output_88xx(struct halmac_adapter * adapter,u8 gpio_id,u8 high)151 pinmux_gpio_output_88xx(struct halmac_adapter *adapter, u8 gpio_id, u8 high)
152 {
153 	u8 value8;
154 	u8 hi_low;
155 	u32 offset;
156 	struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
157 
158 	if (gpio_id <= 7)
159 		offset = REG_GPIO_PIN_CTRL + 1;
160 	else if (gpio_id >= 8 && gpio_id <= 15)
161 		offset = REG_GPIO_EXT_CTRL + 1;
162 	else
163 		return HALMAC_RET_WRONG_GPIO;
164 
165 	hi_low = (high == 0) ? 0 : 1;
166 	gpio_id &= (8 - 1);
167 
168 	value8 = HALMAC_REG_R8(offset);
169 	value8 &= ~(1 << gpio_id);
170 	value8 |= (hi_low << gpio_id);
171 	HALMAC_REG_W8(offset, value8);
172 
173 	return HALMAC_RET_SUCCESS;
174 }
175 
176 /**
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)
181  * Author : Ivan Lin
182  * Return : enum halmac_ret_status
183  * More details of status code can be found in prototype document
184  */
185 enum halmac_ret_status
pinmux_pin_status_88xx(struct halmac_adapter * adapter,u8 pin_id,u8 * high)186 pinmux_pin_status_88xx(struct halmac_adapter *adapter, u8 pin_id, u8 *high)
187 {
188 	u8 value8;
189 	u32 offset;
190 	struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
191 
192 	if (pin_id <= 7)
193 		offset = REG_GPIO_PIN_CTRL;
194 	else if (pin_id >= 8 && pin_id <= 15)
195 		offset = REG_GPIO_EXT_CTRL;
196 	else
197 		return HALMAC_RET_WRONG_GPIO;
198 
199 	pin_id &= (8 - 1);
200 
201 	value8 = HALMAC_REG_R8(offset);
202 	*high = (value8 & (1 << pin_id)) >> pin_id;
203 
204 	return HALMAC_RET_SUCCESS;
205 }
206 
207 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)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)
211 {
212 	u32 i;
213 	u8 value8;
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;
217 
218 	state = &adapter->halmac_state.gpio_cfg_state;
219 
220 	if (*state == HALMAC_GPIO_CFG_STATE_BUSY)
221 		return HALMAC_RET_BUSY_STATE;
222 
223 	*state = HALMAC_GPIO_CFG_STATE_BUSY;
224 
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,
229 				      cur_list->func);
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;
234 		}
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;
239 			break;
240 		}
241 		cur_list++;
242 	}
243 
244 	switch (*cur_func) {
245 	case HALMAC_BT_DPDT_SEL:
246 		*cur_func = (HALMAC_REG_R8(REG_LED_CFG + 3) & BIT(0)) ?
247 				HALMAC_WL_DPDT_SEL : HALMAC_BT_DPDT_SEL;
248 		break;
249 	case HALMAC_BT_PAPE_SEL:
250 		*cur_func = (HALMAC_REG_R8(REG_PAD_CTRL1 + 3) & BIT(5)) ?
251 				HALMAC_WL_PAPE_SEL : HALMAC_BT_PAPE_SEL;
252 		break;
253 	case HALMAC_BT_LNAON_SEL:
254 		*cur_func = (HALMAC_REG_R8(REG_PAD_CTRL1 + 3) & BIT(4)) ?
255 				HALMAC_WL_LNAON_SEL : HALMAC_BT_LNAON_SEL;
256 		break;
257 	default:
258 		break;
259 	}
260 
261 	*state = HALMAC_GPIO_CFG_STATE_IDLE;
262 
263 	if (i == size)
264 		return HALMAC_RET_GET_PINMUX_ERR;
265 
266 	return HALMAC_RET_SUCCESS;
267 }
268 
269 #endif /* HALMAC_88XX_SUPPORT */
270 
271