1 /******************************************************************************
3 * Copyright(c) 2007 - 2016 Realtek Corporation.
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 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
26 /* ************************************************************
28 * *************************************************************/
29 #include "mp_precomp.h"
30 #include "phydm_precomp.h"
32 static inline void phydm_update_rf_state(struct phy_dm_struct *dm,
33 struct dyn_pwr_saving *dm_ps_table,
36 int _is_force_in_normal)
38 if (_is_force_in_normal) {
39 dm_ps_table->cur_rf_state = rf_normal;
43 if (dm->rssi_min == 0xFF) {
44 dm_ps_table->cur_rf_state = RF_MAX;
48 if (dm_ps_table->pre_rf_state == rf_normal) {
49 if (dm->rssi_min >= _rssi_up_bound)
50 dm_ps_table->cur_rf_state = rf_save;
52 dm_ps_table->cur_rf_state = rf_normal;
54 if (dm->rssi_min <= _rssi_low_bound)
55 dm_ps_table->cur_rf_state = rf_normal;
57 dm_ps_table->cur_rf_state = rf_save;
61 void odm_dynamic_bb_power_saving_init(void *dm_void)
63 struct phy_dm_struct *dm = (struct phy_dm_struct *)dm_void;
64 struct dyn_pwr_saving *dm_ps_table = &dm->dm_ps_table;
66 dm_ps_table->pre_cca_state = CCA_MAX;
67 dm_ps_table->cur_cca_state = CCA_MAX;
68 dm_ps_table->pre_rf_state = RF_MAX;
69 dm_ps_table->cur_rf_state = RF_MAX;
70 dm_ps_table->rssi_val_min = 0;
71 dm_ps_table->initialize = 0;
74 void odm_rf_saving(void *dm_void, u8 is_force_in_normal)
76 struct phy_dm_struct *dm = (struct phy_dm_struct *)dm_void;
77 struct dyn_pwr_saving *dm_ps_table = &dm->dm_ps_table;
78 u8 rssi_up_bound = 30;
79 u8 rssi_low_bound = 25;
81 if (dm->patch_id == 40) { /* RT_CID_819x_FUNAI_TV */
85 if (dm_ps_table->initialize == 0) {
87 (odm_get_bb_reg(dm, 0x874, MASKDWORD) & 0x1CC000) >> 14;
89 (odm_get_bb_reg(dm, 0xc70, MASKDWORD) & BIT(3)) >> 3;
91 (odm_get_bb_reg(dm, 0x85c, MASKDWORD) & 0xFF000000) >>
94 (odm_get_bb_reg(dm, 0xa74, MASKDWORD) & 0xF000) >> 12;
95 /* Reg818 = phy_query_bb_reg(adapter, 0x818, MASKDWORD); */
96 dm_ps_table->initialize = 1;
99 phydm_update_rf_state(dm, dm_ps_table, rssi_up_bound, rssi_low_bound,
102 if (dm_ps_table->pre_rf_state != dm_ps_table->cur_rf_state) {
103 if (dm_ps_table->cur_rf_state == rf_save) {
104 odm_set_bb_reg(dm, 0x874, 0x1C0000,
105 0x2); /* reg874[20:18]=3'b010 */
106 odm_set_bb_reg(dm, 0xc70, BIT(3),
107 0); /* regc70[3]=1'b0 */
108 odm_set_bb_reg(dm, 0x85c, 0xFF000000,
109 0x63); /* reg85c[31:24]=0x63 */
110 odm_set_bb_reg(dm, 0x874, 0xC000,
111 0x2); /* reg874[15:14]=2'b10 */
112 odm_set_bb_reg(dm, 0xa74, 0xF000,
113 0x3); /* RegA75[7:4]=0x3 */
114 odm_set_bb_reg(dm, 0x818, BIT(28),
115 0x0); /* Reg818[28]=1'b0 */
116 odm_set_bb_reg(dm, 0x818, BIT(28),
117 0x1); /* Reg818[28]=1'b1 */
119 odm_set_bb_reg(dm, 0x874, 0x1CC000,
120 dm_ps_table->reg874);
121 odm_set_bb_reg(dm, 0xc70, BIT(3), dm_ps_table->regc70);
122 odm_set_bb_reg(dm, 0x85c, 0xFF000000,
123 dm_ps_table->reg85c);
124 odm_set_bb_reg(dm, 0xa74, 0xF000, dm_ps_table->rega74);
125 odm_set_bb_reg(dm, 0x818, BIT(28), 0x0);
127 dm_ps_table->pre_rf_state = dm_ps_table->cur_rf_state;