GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / staging / rtlwifi / halmac / halmac_88xx / halmac_8822b / halmac_api_8822b_usb.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2016  Realtek Corporation.
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  * The full GNU General Public License is included in this distribution in the
15  * file called LICENSE.
16  *
17  * Contact Information:
18  * wlanfae <wlanfae@realtek.com>
19  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20  * Hsinchu 300, Taiwan.
21  *
22  * Larry Finger <Larry.Finger@lwfinger.net>
23  *
24  *****************************************************************************/
25 #include "../halmac_88xx_cfg.h"
26 #include "halmac_8822b_cfg.h"
27
28 /**
29  * halmac_mac_power_switch_8822b_usb() - switch mac power
30  * @halmac_adapter : the adapter of halmac
31  * @halmac_power : power state
32  * Author : KaiYuan Chang
33  * Return : enum halmac_ret_status
34  * More details of status code can be found in prototype document
35  */
36 enum halmac_ret_status
37 halmac_mac_power_switch_8822b_usb(struct halmac_adapter *halmac_adapter,
38                                   enum halmac_mac_power halmac_power)
39 {
40         u8 interface_mask;
41         u8 value8;
42         void *driver_adapter = NULL;
43         struct halmac_api *halmac_api;
44
45         if (halmac_adapter_validate(halmac_adapter) != HALMAC_RET_SUCCESS)
46                 return HALMAC_RET_ADAPTER_INVALID;
47
48         if (halmac_api_validate(halmac_adapter) != HALMAC_RET_SUCCESS)
49                 return HALMAC_RET_API_INVALID;
50
51         halmac_api_record_id_88xx(halmac_adapter, HALMAC_API_MAC_POWER_SWITCH);
52
53         driver_adapter = halmac_adapter->driver_adapter;
54         halmac_api = (struct halmac_api *)halmac_adapter->halmac_api;
55
56         HALMAC_RT_TRACE(
57                 driver_adapter, HALMAC_MSG_PWR, DBG_DMESG,
58                 "halmac_mac_power_switch_88xx_usb halmac_power = %x ==========>\n",
59                 halmac_power);
60
61         interface_mask = HALMAC_PWR_INTF_USB_MSK;
62
63         value8 = HALMAC_REG_READ_8(halmac_adapter, REG_CR);
64         if (value8 == 0xEA) {
65                 halmac_adapter->halmac_state.mac_power = HALMAC_MAC_POWER_OFF;
66         } else {
67                 if (BIT(0) ==
68                     (HALMAC_REG_READ_8(halmac_adapter, REG_SYS_STATUS1 + 1) &
69                      BIT(0)))
70                         halmac_adapter->halmac_state.mac_power =
71                                 HALMAC_MAC_POWER_OFF;
72                 else
73                         halmac_adapter->halmac_state.mac_power =
74                                 HALMAC_MAC_POWER_ON;
75         }
76
77         /*Check if power switch is needed*/
78         if (halmac_power == HALMAC_MAC_POWER_ON &&
79             halmac_adapter->halmac_state.mac_power == HALMAC_MAC_POWER_ON) {
80                 HALMAC_RT_TRACE(
81                         driver_adapter, HALMAC_MSG_PWR, DBG_WARNING,
82                         "halmac_mac_power_switch power state unchange!\n");
83                 return HALMAC_RET_PWR_UNCHANGE;
84         }
85         if (halmac_power == HALMAC_MAC_POWER_OFF) {
86                 if (halmac_pwr_seq_parser_88xx(
87                             halmac_adapter, HALMAC_PWR_CUT_ALL_MSK,
88                             HALMAC_PWR_FAB_TSMC_MSK, interface_mask,
89                             halmac_8822b_card_disable_flow) !=
90                     HALMAC_RET_SUCCESS) {
91                         pr_err("Handle power off cmd error\n");
92                         return HALMAC_RET_POWER_OFF_FAIL;
93                 }
94
95                 halmac_adapter->halmac_state.mac_power = HALMAC_MAC_POWER_OFF;
96                 halmac_adapter->halmac_state.ps_state =
97                         HALMAC_PS_STATE_UNDEFINE;
98                 halmac_adapter->halmac_state.dlfw_state = HALMAC_DLFW_NONE;
99                 halmac_init_adapter_dynamic_para_88xx(halmac_adapter);
100         } else {
101                 if (halmac_pwr_seq_parser_88xx(
102                             halmac_adapter, HALMAC_PWR_CUT_ALL_MSK,
103                             HALMAC_PWR_FAB_TSMC_MSK, interface_mask,
104                             halmac_8822b_card_enable_flow) !=
105                     HALMAC_RET_SUCCESS) {
106                         pr_err("Handle power on cmd error\n");
107                         return HALMAC_RET_POWER_ON_FAIL;
108                 }
109
110                 HALMAC_REG_WRITE_8(
111                         halmac_adapter, REG_SYS_STATUS1 + 1,
112                         HALMAC_REG_READ_8(halmac_adapter, REG_SYS_STATUS1 + 1) &
113                                 ~(BIT(0)));
114
115                 halmac_adapter->halmac_state.mac_power = HALMAC_MAC_POWER_ON;
116                 halmac_adapter->halmac_state.ps_state = HALMAC_PS_STATE_ACT;
117         }
118
119         HALMAC_RT_TRACE(driver_adapter, HALMAC_MSG_PWR, DBG_DMESG,
120                         "halmac_mac_power_switch_88xx_usb <==========\n");
121
122         return HALMAC_RET_SUCCESS;
123 }
124
125 /**
126  * halmac_phy_cfg_8822b_usb() - phy config
127  * @halmac_adapter : the adapter of halmac
128  * Author : KaiYuan Chang
129  * Return : enum halmac_ret_status
130  * More details of status code can be found in prototype document
131  */
132 enum halmac_ret_status
133 halmac_phy_cfg_8822b_usb(struct halmac_adapter *halmac_adapter,
134                          enum halmac_intf_phy_platform platform)
135 {
136         void *driver_adapter = NULL;
137         enum halmac_ret_status status = HALMAC_RET_SUCCESS;
138         struct halmac_api *halmac_api;
139
140         if (halmac_adapter_validate(halmac_adapter) != HALMAC_RET_SUCCESS)
141                 return HALMAC_RET_ADAPTER_INVALID;
142
143         if (halmac_api_validate(halmac_adapter) != HALMAC_RET_SUCCESS)
144                 return HALMAC_RET_API_INVALID;
145
146         halmac_api_record_id_88xx(halmac_adapter, HALMAC_API_PHY_CFG);
147
148         driver_adapter = halmac_adapter->driver_adapter;
149         halmac_api = (struct halmac_api *)halmac_adapter->halmac_api;
150
151         HALMAC_RT_TRACE(driver_adapter, HALMAC_MSG_PWR, DBG_DMESG,
152                         "halmac_phy_cfg ==========>\n");
153
154         status = halmac_parse_intf_phy_88xx(halmac_adapter,
155                                             HALMAC_RTL8822B_USB2_PHY, platform,
156                                             HAL_INTF_PHY_USB2);
157
158         if (status != HALMAC_RET_SUCCESS)
159                 return status;
160
161         status = halmac_parse_intf_phy_88xx(halmac_adapter,
162                                             HALMAC_RTL8822B_USB3_PHY, platform,
163                                             HAL_INTF_PHY_USB3);
164
165         if (status != HALMAC_RET_SUCCESS)
166                 return status;
167
168         HALMAC_RT_TRACE(driver_adapter, HALMAC_MSG_PWR, DBG_DMESG,
169                         "halmac_phy_cfg <==========\n");
170
171         return HALMAC_RET_SUCCESS;
172 }
173
174 /**
175  * halmac_interface_integration_tuning_8822b_usb() - usb interface fine tuning
176  * @halmac_adapter : the adapter of halmac
177  * Author : Ivan
178  * Return : enum halmac_ret_status
179  * More details of status code can be found in prototype document
180  */
181 enum halmac_ret_status halmac_interface_integration_tuning_8822b_usb(
182         struct halmac_adapter *halmac_adapter)
183 {
184         return HALMAC_RET_SUCCESS;
185 }