This source file includes following definitions.
- rtw_hw_suspend
- rtw_hw_resume
- ips_enter
- ips_leave
- rtw_pwr_unassociated_idle
- rtw_ps_processor
- pwr_state_check_handler
- rtw_set_rpwm
- PS_RDY_CHECK
- rtw_set_ps_mode
- LPS_RF_ON_check
- LPS_Enter
- LPS_Leave
- LeaveAllPowerSaveMode
- rtw_init_pwrctrl_priv
- _rtw_pwr_wakeup
- rtw_pm_set_lps
- rtw_pm_set_ips
1
2
3
4
5
6
7 #define _RTW_PWRCTRL_C_
8
9 #include <osdep_service.h>
10 #include <drv_types.h>
11 #include <osdep_intf.h>
12 #include <usb_ops_linux.h>
13 #include <linux/usb.h>
14
15 static int rtw_hw_suspend(struct adapter *padapter)
16 {
17 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
18 struct net_device *pnetdev = padapter->pnetdev;
19
20 if ((!padapter->bup) || (padapter->bDriverStopped) ||
21 (padapter->bSurpriseRemoved)) {
22 DBG_88E("padapter->bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n",
23 padapter->bup, padapter->bDriverStopped,
24 padapter->bSurpriseRemoved);
25 goto error_exit;
26 }
27
28
29 LeaveAllPowerSaveMode(padapter);
30
31 DBG_88E("==> %s\n", __func__);
32 mutex_lock(&pwrpriv->mutex_lock);
33 pwrpriv->bips_processing = true;
34
35 if (pnetdev) {
36 netif_carrier_off(pnetdev);
37 netif_tx_stop_all_queues(pnetdev);
38 }
39
40
41 rtw_disassoc_cmd(padapter, 500, false);
42
43
44 {
45 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
46
47 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
48 _clr_fwstate_(pmlmepriv, _FW_LINKED);
49
50 led_control_8188eu(padapter, LED_CTL_NO_LINK);
51
52 rtw_os_indicate_disconnect(padapter);
53
54
55 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_DISCONNECT, 0);
56 }
57 }
58
59 rtw_free_assoc_resources(padapter);
60
61
62 rtw_free_network_queue(padapter, true);
63 rtw_ips_dev_unload(padapter);
64 pwrpriv->rf_pwrstate = rf_off;
65 pwrpriv->bips_processing = false;
66
67 mutex_unlock(&pwrpriv->mutex_lock);
68
69 return 0;
70
71 error_exit:
72 DBG_88E("%s, failed\n", __func__);
73 return -1;
74 }
75
76 static int rtw_hw_resume(struct adapter *padapter)
77 {
78 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
79 struct net_device *pnetdev = padapter->pnetdev;
80
81
82 DBG_88E("==> %s\n", __func__);
83 mutex_lock(&pwrpriv->mutex_lock);
84 pwrpriv->bips_processing = true;
85 rtw_reset_drv_sw(padapter);
86
87 if (ips_netdrv_open((struct adapter *)rtw_netdev_priv(pnetdev)) != _SUCCESS) {
88 mutex_unlock(&pwrpriv->mutex_lock);
89 goto error_exit;
90 }
91
92 netif_device_attach(pnetdev);
93 netif_carrier_on(pnetdev);
94
95 if (!netif_queue_stopped(pnetdev))
96 netif_start_queue(pnetdev);
97 else
98 netif_wake_queue(pnetdev);
99
100 pwrpriv->bkeepfwalive = false;
101 pwrpriv->brfoffbyhw = false;
102
103 pwrpriv->rf_pwrstate = rf_on;
104 pwrpriv->bips_processing = false;
105
106 mutex_unlock(&pwrpriv->mutex_lock);
107
108 return 0;
109 error_exit:
110 DBG_88E("%s, Open net dev failed\n", __func__);
111 return -1;
112 }
113
114 void ips_enter(struct adapter *padapter)
115 {
116 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
117 struct xmit_priv *pxmit_priv = &padapter->xmitpriv;
118
119 if (padapter->registrypriv.mp_mode == 1)
120 return;
121
122 if (pxmit_priv->free_xmitbuf_cnt != NR_XMITBUFF ||
123 pxmit_priv->free_xmit_extbuf_cnt != NR_XMIT_EXTBUFF) {
124 DBG_88E_LEVEL(_drv_info_, "There are some pkts to transmit\n");
125 DBG_88E_LEVEL(_drv_info_, "free_xmitbuf_cnt: %d, free_xmit_extbuf_cnt: %d\n",
126 pxmit_priv->free_xmitbuf_cnt, pxmit_priv->free_xmit_extbuf_cnt);
127 return;
128 }
129
130 mutex_lock(&pwrpriv->mutex_lock);
131
132 pwrpriv->bips_processing = true;
133
134
135 pwrpriv->ips_mode = pwrpriv->ips_mode_req;
136
137 pwrpriv->ips_enter_cnts++;
138 DBG_88E("==>%s:%d\n", __func__, pwrpriv->ips_enter_cnts);
139 if (rf_off == pwrpriv->change_rfpwrstate) {
140 pwrpriv->bpower_saving = true;
141 DBG_88E_LEVEL(_drv_info_, "nolinked power save enter\n");
142
143 if (pwrpriv->ips_mode == IPS_LEVEL_2)
144 pwrpriv->bkeepfwalive = true;
145
146 rtw_ips_pwr_down(padapter);
147 pwrpriv->rf_pwrstate = rf_off;
148 }
149 pwrpriv->bips_processing = false;
150
151 mutex_unlock(&pwrpriv->mutex_lock);
152 }
153
154 int ips_leave(struct adapter *padapter)
155 {
156 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
157 struct security_priv *psecuritypriv = &(padapter->securitypriv);
158 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
159 int result = _SUCCESS;
160 int keyid;
161
162 mutex_lock(&pwrpriv->mutex_lock);
163
164 if ((pwrpriv->rf_pwrstate == rf_off) && (!pwrpriv->bips_processing)) {
165 pwrpriv->bips_processing = true;
166 pwrpriv->change_rfpwrstate = rf_on;
167 pwrpriv->ips_leave_cnts++;
168 DBG_88E("==>%s:%d\n", __func__, pwrpriv->ips_leave_cnts);
169
170 result = rtw_ips_pwr_up(padapter);
171 if (result == _SUCCESS)
172 pwrpriv->rf_pwrstate = rf_on;
173
174 DBG_88E_LEVEL(_drv_info_, "nolinked power save leave\n");
175
176 if ((_WEP40_ == psecuritypriv->dot11PrivacyAlgrthm) || (_WEP104_ == psecuritypriv->dot11PrivacyAlgrthm)) {
177 DBG_88E("==>%s, channel(%d), processing(%x)\n", __func__, padapter->mlmeextpriv.cur_channel, pwrpriv->bips_processing);
178 set_channel_bwmode(padapter, padapter->mlmeextpriv.cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
179 for (keyid = 0; keyid < 4; keyid++) {
180 if (pmlmepriv->key_mask & BIT(keyid)) {
181 if (keyid == psecuritypriv->dot11PrivacyKeyIndex)
182 result = rtw_set_key(padapter, psecuritypriv, keyid, 1);
183 else
184 result = rtw_set_key(padapter, psecuritypriv, keyid, 0);
185 }
186 }
187 }
188
189 DBG_88E("==> %s.....LED(0x%08x)...\n", __func__, usb_read32(padapter, 0x4c));
190 pwrpriv->bips_processing = false;
191
192 pwrpriv->bkeepfwalive = false;
193 pwrpriv->bpower_saving = false;
194 }
195
196 mutex_unlock(&pwrpriv->mutex_lock);
197
198 return result;
199 }
200
201 static bool rtw_pwr_unassociated_idle(struct adapter *adapter)
202 {
203 struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
204 bool ret = false;
205
206 if (time_after_eq(adapter->pwrctrlpriv.ips_deny_time, jiffies))
207 goto exit;
208
209 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR) ||
210 check_fwstate(pmlmepriv, WIFI_UNDER_LINKING|WIFI_UNDER_WPS) ||
211 check_fwstate(pmlmepriv, WIFI_AP_STATE) ||
212 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_ADHOC_STATE))
213 goto exit;
214
215 ret = true;
216
217 exit:
218 return ret;
219 }
220
221 void rtw_ps_processor(struct adapter *padapter)
222 {
223 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
224 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
225 enum rt_rf_power_state rfpwrstate;
226
227 pwrpriv->ps_processing = true;
228
229 if (pwrpriv->bips_processing)
230 goto exit;
231
232 if (padapter->pwrctrlpriv.bHWPwrPindetect) {
233 rfpwrstate = RfOnOffDetect(padapter);
234 DBG_88E("@@@@- #2 %s==> rfstate:%s\n", __func__, (rfpwrstate == rf_on) ? "rf_on" : "rf_off");
235
236 if (rfpwrstate != pwrpriv->rf_pwrstate) {
237 if (rfpwrstate == rf_off) {
238 pwrpriv->change_rfpwrstate = rf_off;
239 pwrpriv->brfoffbyhw = true;
240 rtw_hw_suspend(padapter);
241 } else {
242 pwrpriv->change_rfpwrstate = rf_on;
243 rtw_hw_resume(padapter);
244 }
245 DBG_88E("current rf_pwrstate(%s)\n", (pwrpriv->rf_pwrstate == rf_off) ? "rf_off" : "rf_on");
246 }
247 pwrpriv->pwr_state_check_cnts++;
248 }
249
250 if (pwrpriv->ips_mode_req == IPS_NONE)
251 goto exit;
252
253 if (!rtw_pwr_unassociated_idle(padapter))
254 goto exit;
255
256 if ((pwrpriv->rf_pwrstate == rf_on) && ((pwrpriv->pwr_state_check_cnts%4) == 0)) {
257 DBG_88E("==>%s .fw_state(%x)\n", __func__, get_fwstate(pmlmepriv));
258 pwrpriv->change_rfpwrstate = rf_off;
259
260 ips_enter(padapter);
261 }
262 exit:
263 rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv);
264 pwrpriv->ps_processing = false;
265 }
266
267 static void pwr_state_check_handler(struct timer_list *t)
268 {
269 struct adapter *padapter =
270 from_timer(padapter, t,
271 pwrctrlpriv.pwr_state_check_timer);
272
273 rtw_ps_cmd(padapter);
274 }
275
276
277
278
279
280
281
282
283 void rtw_set_rpwm(struct adapter *padapter, u8 pslv)
284 {
285 u8 rpwm;
286 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
287
288 pslv = PS_STATE(pslv);
289
290 if (pwrpriv->btcoex_rfon) {
291 if (pslv < PS_STATE_S4)
292 pslv = PS_STATE_S3;
293 }
294
295 if (pwrpriv->rpwm == pslv) {
296 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
297 ("%s: Already set rpwm[0x%02X], new=0x%02X!\n", __func__, pwrpriv->rpwm, pslv));
298 return;
299 }
300
301 if ((padapter->bSurpriseRemoved) ||
302 (!padapter->hw_init_completed)) {
303 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
304 ("%s: SurpriseRemoved(%d) hw_init_completed(%d)\n",
305 __func__, padapter->bSurpriseRemoved, padapter->hw_init_completed));
306
307 pwrpriv->cpwm = PS_STATE_S4;
308
309 return;
310 }
311
312 if (padapter->bDriverStopped) {
313 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
314 ("%s: change power state(0x%02X) when DriverStopped\n", __func__, pslv));
315
316 if (pslv < PS_STATE_S2) {
317 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
318 ("%s: Reject to enter PS_STATE(0x%02X) lower than S2 when DriverStopped!!\n", __func__, pslv));
319 return;
320 }
321 }
322
323 rpwm = pslv | pwrpriv->tog;
324 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
325 ("%s: rpwm=0x%02x cpwm=0x%02x\n", __func__, rpwm, pwrpriv->cpwm));
326
327 pwrpriv->rpwm = pslv;
328
329 rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&rpwm));
330
331 pwrpriv->tog += 0x80;
332 pwrpriv->cpwm = pslv;
333 }
334
335 static u8 PS_RDY_CHECK(struct adapter *padapter)
336 {
337 unsigned long curr_time, delta_time;
338 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
339 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
340
341 curr_time = jiffies;
342 delta_time = curr_time - pwrpriv->DelayLPSLastTimeStamp;
343
344 if (delta_time < LPS_DELAY_TIME)
345 return false;
346
347 if ((!check_fwstate(pmlmepriv, _FW_LINKED)) ||
348 (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) ||
349 (check_fwstate(pmlmepriv, WIFI_AP_STATE)) ||
350 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) ||
351 (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)))
352 return false;
353 if (pwrpriv->bInSuspend)
354 return false;
355 if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X &&
356 !padapter->securitypriv.binstallGrpkey) {
357 DBG_88E("Group handshake still in progress !!!\n");
358 return false;
359 }
360 return true;
361 }
362
363 void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_ant_mode)
364 {
365 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
366
367 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
368 ("%s: PowerMode=%d Smart_PS=%d\n",
369 __func__, ps_mode, smart_ps));
370
371 if (ps_mode > PM_Card_Disable) {
372 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_, ("ps_mode:%d error\n", ps_mode));
373 return;
374 }
375
376 if (pwrpriv->pwr_mode == ps_mode) {
377 if (ps_mode == PS_MODE_ACTIVE)
378 return;
379
380 if ((pwrpriv->smart_ps == smart_ps) &&
381 (pwrpriv->bcn_ant_mode == bcn_ant_mode))
382 return;
383 }
384
385
386 if (ps_mode == PS_MODE_ACTIVE) {
387 if (PS_RDY_CHECK(padapter)) {
388 DBG_88E("%s: Enter 802.11 power save\n", __func__);
389 pwrpriv->bFwCurrentInPSMode = true;
390 pwrpriv->pwr_mode = ps_mode;
391 pwrpriv->smart_ps = smart_ps;
392 pwrpriv->bcn_ant_mode = bcn_ant_mode;
393 rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
394 rtw_set_rpwm(padapter, PS_STATE_S2);
395 }
396 }
397 }
398
399
400
401
402
403
404
405 s32 LPS_RF_ON_check(struct adapter *padapter, u32 delay_ms)
406 {
407 unsigned long start_time;
408 u8 bAwake = false;
409 s32 err = 0;
410
411 start_time = jiffies;
412 while (1) {
413 rtw_hal_get_hwreg(padapter, HW_VAR_FWLPS_RF_ON, &bAwake);
414 if (bAwake)
415 break;
416
417 if (padapter->bSurpriseRemoved) {
418 err = -2;
419 DBG_88E("%s: device surprise removed!!\n", __func__);
420 break;
421 }
422
423 if (jiffies_to_msecs(jiffies - start_time) > delay_ms) {
424 err = -1;
425 DBG_88E("%s: Wait for FW LPS leave more than %u ms!!!\n", __func__, delay_ms);
426 break;
427 }
428 msleep(1);
429 }
430
431 return err;
432 }
433
434
435
436
437
438 void LPS_Enter(struct adapter *padapter)
439 {
440 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
441
442 if (!PS_RDY_CHECK(padapter))
443 return;
444
445 if (pwrpriv->bLeisurePs) {
446
447 if (pwrpriv->LpsIdleCount >= 2) {
448 if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) {
449 pwrpriv->bpower_saving = true;
450 DBG_88E("%s smart_ps:%d\n", __func__, pwrpriv->smart_ps);
451
452 rtw_set_ps_mode(padapter, pwrpriv->power_mgnt, pwrpriv->smart_ps, 0);
453 }
454 } else {
455 pwrpriv->LpsIdleCount++;
456 }
457 }
458 }
459
460 #define LPS_LEAVE_TIMEOUT_MS 100
461
462
463
464 void LPS_Leave(struct adapter *padapter)
465 {
466 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
467
468 if (pwrpriv->bLeisurePs) {
469 if (pwrpriv->pwr_mode != PS_MODE_ACTIVE) {
470 rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0);
471
472 if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
473 LPS_RF_ON_check(padapter, LPS_LEAVE_TIMEOUT_MS);
474 }
475 }
476
477 pwrpriv->bpower_saving = false;
478 }
479
480
481
482
483
484 void LeaveAllPowerSaveMode(struct adapter *Adapter)
485 {
486 struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
487 u8 enqueue = 0;
488
489 if (check_fwstate(pmlmepriv, _FW_LINKED))
490 rtw_lps_ctrl_wk_cmd(Adapter, LPS_CTRL_LEAVE, enqueue);
491 }
492
493 void rtw_init_pwrctrl_priv(struct adapter *padapter)
494 {
495 struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
496
497 mutex_init(&pwrctrlpriv->mutex_lock);
498 pwrctrlpriv->rf_pwrstate = rf_on;
499 pwrctrlpriv->ips_enter_cnts = 0;
500 pwrctrlpriv->ips_leave_cnts = 0;
501 pwrctrlpriv->bips_processing = false;
502
503 pwrctrlpriv->ips_mode = padapter->registrypriv.ips_mode;
504 pwrctrlpriv->ips_mode_req = padapter->registrypriv.ips_mode;
505
506 pwrctrlpriv->pwr_state_check_interval = RTW_PWR_STATE_CHK_INTERVAL;
507 pwrctrlpriv->pwr_state_check_cnts = 0;
508 pwrctrlpriv->bInternalAutoSuspend = false;
509 pwrctrlpriv->bInSuspend = false;
510 pwrctrlpriv->bkeepfwalive = false;
511
512 pwrctrlpriv->LpsIdleCount = 0;
513 if (padapter->registrypriv.mp_mode == 1)
514 pwrctrlpriv->power_mgnt = PS_MODE_ACTIVE;
515 else
516 pwrctrlpriv->power_mgnt = padapter->registrypriv.power_mgnt;
517 pwrctrlpriv->bLeisurePs = (pwrctrlpriv->power_mgnt != PS_MODE_ACTIVE) ? true : false;
518
519 pwrctrlpriv->bFwCurrentInPSMode = false;
520
521 pwrctrlpriv->rpwm = 0;
522 pwrctrlpriv->cpwm = PS_STATE_S4;
523
524 pwrctrlpriv->pwr_mode = PS_MODE_ACTIVE;
525 pwrctrlpriv->smart_ps = padapter->registrypriv.smart_ps;
526 pwrctrlpriv->bcn_ant_mode = 0;
527
528 pwrctrlpriv->tog = 0x80;
529
530 pwrctrlpriv->btcoex_rfon = false;
531
532 timer_setup(&pwrctrlpriv->pwr_state_check_timer,
533 pwr_state_check_handler, 0);
534 }
535
536
537
538
539
540
541
542
543 int _rtw_pwr_wakeup(struct adapter *padapter, u32 ips_deffer_ms, const char *caller)
544 {
545 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
546 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
547 unsigned long expires;
548 unsigned long start;
549 int ret = _SUCCESS;
550
551 expires = jiffies + msecs_to_jiffies(ips_deffer_ms);
552 if (time_before(pwrpriv->ips_deny_time, expires))
553 pwrpriv->ips_deny_time = jiffies + msecs_to_jiffies(ips_deffer_ms);
554
555 start = jiffies;
556 if (pwrpriv->ps_processing) {
557 DBG_88E("%s wait ps_processing...\n", __func__);
558 while (pwrpriv->ps_processing &&
559 jiffies_to_msecs(jiffies - start) <= 3000)
560 udelay(1500);
561 if (pwrpriv->ps_processing)
562 DBG_88E("%s wait ps_processing timeout\n", __func__);
563 else
564 DBG_88E("%s wait ps_processing done\n", __func__);
565 }
566
567
568 if ((!pwrpriv->bInternalAutoSuspend) && (pwrpriv->bInSuspend)) {
569 ret = _FAIL;
570 goto exit;
571 }
572
573
574 if ((pwrpriv->bInternalAutoSuspend) && (padapter->net_closed)) {
575 ret = _FAIL;
576 goto exit;
577 }
578
579
580 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
581 ret = _SUCCESS;
582 goto exit;
583 }
584 if (rf_off == pwrpriv->rf_pwrstate) {
585 DBG_88E("%s call ips_leave....\n", __func__);
586 if (ips_leave(padapter) == _FAIL) {
587 DBG_88E("======> ips_leave fail.............\n");
588 ret = _FAIL;
589 goto exit;
590 }
591 }
592
593
594 if (padapter->bDriverStopped || !padapter->bup ||
595 !padapter->hw_init_completed) {
596 DBG_88E("%s: bDriverStopped=%d, bup=%d, hw_init_completed =%u\n"
597 , caller
598 , padapter->bDriverStopped
599 , padapter->bup
600 , padapter->hw_init_completed);
601 ret = false;
602 goto exit;
603 }
604
605 exit:
606 expires = jiffies + msecs_to_jiffies(ips_deffer_ms);
607 if (time_before(pwrpriv->ips_deny_time, expires))
608 pwrpriv->ips_deny_time = jiffies + msecs_to_jiffies(ips_deffer_ms);
609 return ret;
610 }
611
612 int rtw_pm_set_lps(struct adapter *padapter, u8 mode)
613 {
614 int ret = 0;
615 struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
616
617 if (mode < PS_MODE_NUM) {
618 if (pwrctrlpriv->power_mgnt != mode) {
619 if (mode == PS_MODE_ACTIVE)
620 LeaveAllPowerSaveMode(padapter);
621 else
622 pwrctrlpriv->LpsIdleCount = 2;
623 pwrctrlpriv->power_mgnt = mode;
624 pwrctrlpriv->bLeisurePs = (pwrctrlpriv->power_mgnt != PS_MODE_ACTIVE) ? true : false;
625 }
626 } else {
627 ret = -EINVAL;
628 }
629
630 return ret;
631 }
632
633 int rtw_pm_set_ips(struct adapter *padapter, u8 mode)
634 {
635 struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
636
637 if (mode == IPS_NORMAL || mode == IPS_LEVEL_2) {
638 rtw_ips_mode_req(pwrctrlpriv, mode);
639 DBG_88E("%s %s\n", __func__, mode == IPS_NORMAL ? "IPS_NORMAL" : "IPS_LEVEL_2");
640 return 0;
641 } else if (mode == IPS_NONE) {
642 rtw_ips_mode_req(pwrctrlpriv, mode);
643 DBG_88E("%s %s\n", __func__, "IPS_NONE");
644 if ((padapter->bSurpriseRemoved == 0) && (rtw_pwr_wakeup(padapter) == _FAIL))
645 return -EFAULT;
646 } else {
647 return -EINVAL;
648 }
649 return 0;
650 }