OSDN Git Service

Add rtl8821ce driver version 5.5.2
[android-x86/external-kernel-drivers.git] / rtl8821ce / hal / halmac / halmac_88xx / halmac_8821c / halmac_common_8821c.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2017 - 2018 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_8821c_cfg.h"
17 #include "halmac_common_8821c.h"
18 #include "../halmac_common_88xx.h"
19 #include "halmac_cfg_wmac_8821c.h"
20 #if HALMAC_PCIE_SUPPORT
21 #include "halmac_pcie_8821c.h"
22 #endif
23
24 #if HALMAC_8821C_SUPPORT
25
26 static void
27 cfg_ldo25_8821c(struct halmac_adapter *adapter, u8 enable);
28
29 /**
30  * get_hw_value_8821c() -get hw config value
31  * @adapter : the adapter of halmac
32  * @hw_id : hw id for driver to query
33  * @value : hw value, reference table to get data type
34  * Author : KaiYuan Chang / Ivan Lin
35  * Return : enum halmac_ret_status
36  * More details of status code can be found in prototype document
37  */
38 enum halmac_ret_status
39 get_hw_value_8821c(struct halmac_adapter *adapter, enum halmac_hw_id hw_id,
40                    void *value)
41 {
42         PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
43
44         if (!value) {
45                 PLTFM_MSG_ERR("[ERR]null pointer\n");
46                 return HALMAC_RET_NULL_POINTER;
47         }
48
49         if (get_hw_value_88xx(adapter, hw_id, value) == HALMAC_RET_SUCCESS)
50                 return HALMAC_RET_SUCCESS;
51
52         switch (hw_id) {
53         case HALMAC_HW_FW_MAX_SIZE:
54                 *(u32 *)value = WLAN_FW_MAX_SIZE_8821C;
55                 break;
56         case HALMAC_HW_SDIO_INT_LAT:
57                 break;
58         case HALMAC_HW_SDIO_CLK_CNT:
59                 break;
60         default:
61                 return HALMAC_RET_PARA_NOT_SUPPORT;
62         }
63
64         PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
65
66         return HALMAC_RET_SUCCESS;
67 }
68
69 /**
70  * set_hw_value_8821c() -set hw config value
71  * @adapter : the adapter of halmac
72  * @hw_id : hw id for driver to config
73  * @value : hw value, reference table to get data type
74  * Author : KaiYuan Chang / Ivan Lin
75  * Return : enum halmac_ret_status
76  * More details of status code can be found in prototype document
77  */
78 enum halmac_ret_status
79 set_hw_value_8821c(struct halmac_adapter *adapter, enum halmac_hw_id hw_id,
80                    void *value)
81 {
82         enum halmac_ret_status status = HALMAC_RET_SUCCESS;
83
84         PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
85
86         if (!value) {
87                 PLTFM_MSG_ERR("[ERR]null pointer\n");
88                 return HALMAC_RET_NULL_POINTER;
89         }
90
91         if (set_hw_value_88xx(adapter, hw_id, value) == HALMAC_RET_SUCCESS)
92                 return HALMAC_RET_SUCCESS;
93
94         switch (hw_id) {
95         case HALMAC_HW_AMPDU_CONFIG:
96                 status = cfg_ampdu_8821c(adapter,
97                                          (struct halmac_ampdu_config *)value);
98                 break;
99         case HALMAC_HW_SDIO_TX_FORMAT:
100                 break;
101         case HALMAC_HW_RXGCK_FIFO:
102                 break;
103         case HALMAC_HW_RX_IGNORE:
104                 break;
105         case HALMAC_HW_LDO25_EN:
106                 cfg_ldo25_8821c(adapter, *(u8 *)value);
107                 break;
108 #if HALMAC_PCIE_SUPPORT
109         case HALMAC_HW_PCIE_REF_AUTOK:
110                 if (adapter->intf != HALMAC_INTERFACE_PCIE)
111                         return HALMAC_RET_WRONG_INTF;
112                 status = auto_refclk_cal_8821c_pcie(adapter);
113                 if (status != HALMAC_RET_SUCCESS)
114                         return status;
115                 break;
116 #endif
117         case HALMAC_HW_SDIO_WT_EN:
118                 break;
119         case HALMAC_HW_SDIO_CLK_MONITOR:
120                 break;
121         default:
122                 return HALMAC_RET_PARA_NOT_SUPPORT;
123         }
124
125         PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
126
127         return status;
128 }
129
130 /**
131  * halmac_fill_txdesc_check_sum_88xx() -  fill in tx desc check sum
132  * @adapter : the adapter of halmac
133  * @txdesc : tx desc packet
134  * Author : KaiYuan Chang/Ivan Lin
135  * Return : enum halmac_ret_status
136  * More details of status code can be found in prototype document
137  */
138 enum halmac_ret_status
139 fill_txdesc_check_sum_8821c(struct halmac_adapter *adapter, u8 *txdesc)
140 {
141         __le16 chksum = 0;
142         __le16 *data;
143         u32 i;
144
145         if (!txdesc) {
146                 PLTFM_MSG_ERR("[ERR]null pointer\n");
147                 return HALMAC_RET_NULL_POINTER;
148         }
149
150         if (adapter->tx_desc_checksum != 1)
151                 PLTFM_MSG_TRACE("[TRACE]chksum disable\n");
152
153         SET_TX_DESC_TXDESC_CHECKSUM(txdesc, 0x0000);
154
155         data = (__le16 *)(txdesc);
156
157         /* HW clculates only 32byte */
158         for (i = 0; i < 8; i++)
159                 chksum ^= (*(data + 2 * i) ^ *(data + (2 * i + 1)));
160
161         /* *(data + 2 * i) & *(data + (2 * i + 1) have endain issue*/
162         /* Process eniadn issue after checksum calculation */
163         SET_TX_DESC_TXDESC_CHECKSUM(txdesc, rtk_le16_to_cpu(chksum));
164
165         return HALMAC_RET_SUCCESS;
166 }
167
168 static void
169 cfg_ldo25_8821c(struct halmac_adapter *adapter, u8 enable)
170 {
171         u8 value8;
172         struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
173
174         value8 = HALMAC_REG_R8(REG_LDO_EFUSE_CTRL + 3);
175
176         if (enable == 1)
177                 HALMAC_REG_W8(REG_LDO_EFUSE_CTRL + 3, (u8)(value8 | BIT(7)));
178         else
179                 HALMAC_REG_W8(REG_LDO_EFUSE_CTRL + 3, (u8)(value8 & ~BIT(7)));
180 }
181
182 #endif /* HALMAC_8821C_SUPPORT */