wifi: rt2x00: limit MT7620 TX power based on eeprom calibration
authorShiji Yang <yangshiji66@outlook.com>
Fri, 11 Aug 2023 06:34:54 +0000 (14:34 +0800)
committerKalle Valo <kvalo@kernel.org>
Wed, 23 Aug 2023 11:09:48 +0000 (14:09 +0300)
commit821b5192c955144bd2f0aeea6cd153e1aedd16e1
treeef99db3ffb5270ff86cb9f1cbc8cd1fd6a92b70d
parenteaa8023e9bb30926b154af72be0cadbebfc8e878
wifi: rt2x00: limit MT7620 TX power based on eeprom calibration

In the vendor driver, the current channel power is queried from
EEPROM_TXPOWER_BG1 and EEPROM_TXPOWER_BG2. And then the mixed value
will be written into the low half-word of the TX_ALC_CFG_0 register.
The high half-word of the TX_ALC_CFG_0 is a fixed value 0x2f2f.

We can't get the accurate TX power. Based on my tests and the new
MediaTek mt76 driver source code, the real TX power is approximately
equal to channel_power + (max) rate_power. Usually max rate_power is
the gain of the OFDM 6M rate, which can be readed from the offset
EEPROM_TXPOWER_BYRATE +1.

Based on these eeprom values, this patch adds basic TX power control
for the MT7620 and limits its maximum TX power. This can avoid the
link speed decrease caused by chip overheating. rt2800_config_alc()
function has also been renamed to rt2800_config_alc_rt6352() because
it's only used by RT6352 (MT7620).

Notice:
It's still need some work to sync the max channel power to the user
interface. This part is missing from the rt2x00 driver framework. If
we set the power exceed the calibration value, it won't take effect.

Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
Acked-by: Stanislaw Gruszka <stf_xl@wp.pl>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/TYAP286MB03159090ED14044215E59FD6BC10A@TYAP286MB0315.JPNP286.PROD.OUTLOOK.COM
drivers/net/wireless/ralink/rt2x00/rt2800lib.c