461 lines
22 KiB
C
461 lines
22 KiB
C
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
|
|
#include "bb_init.h"
|
|
#include "bb_rf_cfg.h"
|
|
#include "iot_errno_api.h"
|
|
#include "iot_config.h"
|
|
#include "os_utils.h"
|
|
#include "hw_reg_api.h"
|
|
#include "rfplc_reg_base.h"
|
|
#include "wphy_reg.h"
|
|
#include "mac_sys_reg.h"
|
|
#include "bb_rf_tone_tbl.h"
|
|
#include "bb_cpu_config.h"
|
|
#include "iot_irq.h"
|
|
#include "phy_rf_chn.h"
|
|
#include "rf_spi_api.h"
|
|
#include "bb_cpu_utils.h"
|
|
#include "mac_rf_common_hw.h"
|
|
|
|
static void rf_init_cfg(uint8_t option, uint8_t rf_ver)
|
|
{
|
|
int8_t default_power;
|
|
/* Config RF regs using SPI */
|
|
if (rf_ver == RF_VER_3) {
|
|
if (!mac_rf_is_rf_in()) {
|
|
rf_spi_write(0, 0x6FBE & (~((!!HPLC_RF_RX_BPF_EN) << 7)));
|
|
} else {
|
|
/* RF sealed chip, PLL using external power supply, internal PLL ldo
|
|
* should power down
|
|
*/
|
|
rf_spi_write(0, 0x2FBE & (~((!!HPLC_RF_RX_BPF_EN) << 7)));
|
|
}
|
|
#if HPLC_RF_RX_BPF_EN
|
|
/* when rx filter is operating in BPF mode, it is necessary to turn off
|
|
* the rx DC automatic compensation circuit.
|
|
*/
|
|
rf_spi_write(1 , 0x03d9);
|
|
#else /* HPLC_RF_RX_BPF_EN */
|
|
/* when rx filter is operating in LPF mode, it is necessary to turn on
|
|
* the rx DC automatic compensation circuit.
|
|
*/
|
|
rf_spi_write(1, 0x03C3);
|
|
#endif /* HPLC_RF_RX_BPF_EN */
|
|
rf_spi_write(2, 0x8AB4);
|
|
rf_spi_write(3, 0xA4CE);
|
|
rf_spi_write(4, 0xFBC7);
|
|
rf_spi_write(5, 0xA7FC);
|
|
if (HPLC_RF_RX_BPF_EN && option == PHY_RF_OPTION3_200K) {
|
|
rf_spi_write(6, 0x68df);
|
|
rf_spi_write(7, 0x9B13);
|
|
rf_spi_write(23, 0x0C00);
|
|
} else if (HPLC_RF_RX_BPF_EN && option == PHY_RF_OPTION2_500K) {
|
|
rf_spi_write(6, 0x6818);
|
|
rf_spi_write(7, 0x299B);
|
|
rf_spi_write(23, 0x1400);
|
|
} else {
|
|
rf_spi_write(6, 0x6887);
|
|
rf_spi_write(7, 0x29D7);
|
|
rf_spi_write(23, 0x3C00);
|
|
}
|
|
//rf_spi_write(8 , 0x0000);
|
|
rf_spi_write(9 , 0x0000);
|
|
rf_spi_write(10, 0x0081);
|
|
rf_spi_write(11, 0xC000);
|
|
rf_spi_write(12, 0x01FF);
|
|
rf_spi_write(13, 0x503B);
|
|
rf_spi_write(14, 0x2003);
|
|
rf_spi_write(15, 0x302E);
|
|
rf_spi_write(16, 0x8430);
|
|
rf_spi_write(17, 0x29CE);
|
|
rf_spi_write(18, 0x5604);
|
|
rf_spi_write(19, 0x1800);
|
|
//rf_spi_write(24, 0x0BFD);
|
|
rf_spi_write(29, 0x0000);
|
|
// r30 bit8 = 0 -> off mclk
|
|
rf_spi_write(30, 0xE001);
|
|
rf_spi_write(31, 0x3000);
|
|
#if HPLC_RF_RX_BPF_EN
|
|
/* r32 defauilt config fllow:
|
|
* r32<12> set to 1: sys clock off
|
|
* r32<7> set to 0: RX BPF/LPF mode select as "BPF"
|
|
* r32<6> set to 6: RX BPF side-band select as "Lower side-band"
|
|
*/
|
|
rf_spi_write(32, 0x1045);
|
|
#else /* HPLC_RF_RX_BPF_EN */
|
|
/* r32 defauilt config fllow:
|
|
* r32<12> set to 1: sys clock off
|
|
* r32<7> set to 1: RX BPF/LPF mode select as "LPF"
|
|
*/
|
|
rf_spi_write(32, 0x1080);
|
|
#endif /* HPLC_RF_RX_BPF_EN */
|
|
|
|
} else if (RF_VER_2 == rf_ver) {
|
|
rf_spi_write(0, 0x6BBE);
|
|
rf_spi_write(1, 0x02C0);
|
|
rf_spi_write(2, 0x8AB4);
|
|
rf_spi_write(3, 0xA4CA);
|
|
rf_spi_write(4, 0xF7DF);
|
|
rf_spi_write(5, 0x67FE);
|
|
rf_spi_write(6, 0x4800);
|
|
rf_spi_write(7, 0x1080);
|
|
//rf_spi_write(8 , 0x0000);
|
|
//rf_spi_write(9 , 0x0000);
|
|
rf_spi_write(10, 0x0001);
|
|
rf_spi_write(11, 0x0000);
|
|
rf_spi_write(12, 0x03FF);
|
|
rf_spi_write(13, 0x703B);
|
|
rf_spi_write(14, 0x2003);
|
|
rf_spi_write(15, 0x584E);
|
|
rf_spi_write(16, 0xC030);
|
|
rf_spi_write(17, 0x29CE);
|
|
rf_spi_write(18, 0x5604);
|
|
rf_spi_write(19, 0x1800);
|
|
//rf_spi_write(23, 0x0000);
|
|
//rf_spi_write(24, 0x0BF7);
|
|
rf_spi_write(29, 0x0000);
|
|
// r30 bit8 = 0 -> off mclk
|
|
rf_spi_write(30, 0x6001);
|
|
rf_spi_write(31, 0x2000);
|
|
// r32 bit12 = 1 -> off sysclk
|
|
rf_spi_write(32, 0x1000);
|
|
rf_spi_write(33, 0x0000);
|
|
} else {
|
|
rf_spi_write(0 , 0xEBBA);
|
|
rf_spi_write(1 , 0x02C1);
|
|
rf_spi_write(2 , 0x8AB4);
|
|
rf_spi_write(3 , 0xA4CA);
|
|
rf_spi_write(4 , 0xFFC6);
|
|
rf_spi_write(5 , 0xA692);
|
|
rf_spi_write(6 , 0x4800);
|
|
rf_spi_write(7 , 0x1087);
|
|
//rf_spi_write(8 , 0x0000);
|
|
//rf_spi_write(9 , 0x0000);
|
|
rf_spi_write(10, 0x0000);
|
|
rf_spi_write(11, 0x3023);
|
|
rf_spi_write(12, 0x03FF);
|
|
rf_spi_write(13, 0xB03B);
|
|
rf_spi_write(14, 0x2003);
|
|
rf_spi_write(15, 0x584E);
|
|
rf_spi_write(16, 0xC030);
|
|
rf_spi_write(17, 0x29B9);
|
|
rf_spi_write(18, 0xDB22);
|
|
rf_spi_write(19, 0x1800);
|
|
//rf_spi_write(23, 0x0000);
|
|
//rf_spi_write(24, 0x0BEF);
|
|
rf_spi_write(29, 0x5509);
|
|
rf_spi_write(30, 0x6001);
|
|
rf_spi_write(31, 0x0000);
|
|
rf_spi_write(32, 0x0000);
|
|
rf_spi_write(33, 0x0000);
|
|
}
|
|
bb_rf_update_cali(option);
|
|
phy_rf_get_power(NULL, NULL, &default_power, NULL);
|
|
bb_rf_set_pa(1, default_power);
|
|
}
|
|
|
|
void bb_rf_init(uint32_t option, uint32_t pa_init_only)
|
|
{
|
|
uint32_t i;
|
|
IOT_ASSERT(option < PHY_RF_OPTION_MAX);
|
|
uint8_t rf_ver = bb_rf_get_ver();
|
|
rf_init_cfg(option, rf_ver);
|
|
|
|
if (pa_init_only) {
|
|
return;
|
|
}
|
|
|
|
#if BB_CPU_DEBUG_PRINT
|
|
for (uint32_t i = 0; i < 34; i++) {
|
|
bb_cpu_printf("spi read i:%d, 0x%x\n", i, rf_spi_read(i));
|
|
}
|
|
bb_cpu_printf("rf power:%d\n", bb_rf_get_pa(1));
|
|
#endif
|
|
|
|
// Config BB regs using APB
|
|
WPHY_INIT_WRITE_REG(0xf00010, ((option==1) ? 0x64514F29 : (option==2) ? 0x64514F29 : 0x64514F29));
|
|
WPHY_INIT_WRITE_REG(0xf0166c, ((option==1) ? 0x06be0637 : (option==2) ? 0x06be0637 : 0x042b0407));
|
|
WPHY_INIT_WRITE_REG(0xf01214, ((option==1) ? 0x00606060 : (option==2) ? 0x00303030 : 0x00121212));
|
|
WPHY_INIT_WRITE_REG(0xf01624, ((option==1) ? 0x3fc83ff0 : (option==2) ? 0x3fc83ff0 : 0x3fcd000e));
|
|
WPHY_INIT_WRITE_REG(0xf01568, ((option==1) ? 0x00000f2d : (option==2) ? 0x00000f2d : 0x00000e6a));
|
|
WPHY_INIT_WRITE_REG(0xf0100c, ((option==1) ? 0x68087007 : (option==2) ? 0x34047006 : 0x14023005));
|
|
WPHY_INIT_WRITE_REG(0xf01410, ((option==1) ? 0x00000021 : (option==2) ? 0x00000051 : 0x00000071));
|
|
WPHY_INIT_WRITE_REG(0xf01558, ((option==1) ? 0x00f2df2d : (option==2) ? 0x00f2df2d : 0x000cb000));
|
|
WPHY_INIT_WRITE_REG(0xf01014, ((option==1) ? 0xff00ffff : (option==2) ? 0x0003f0ff : 0x000001cf));
|
|
WPHY_INIT_WRITE_REG(0xf01018, ((option==1) ? 0x8000000f : (option==2) ? 0x80000000 : 0x80000000));
|
|
WPHY_INIT_WRITE_REG(0xf01300, ((option==1) ? 0x00110000 : (option==2) ? 0x00110000 : 0x00110000));
|
|
WPHY_INIT_WRITE_REG(0xf01024, ((option==1) ? 0x0000740c : (option==2) ? 0x00003a06 : 0x00001e02));
|
|
WPHY_INIT_WRITE_REG(0xf01028, ((option==1) ? 0x00181853 : (option==2) ? 0x000c0c53 : 0x00040453));
|
|
WPHY_INIT_WRITE_REG(0xf0155c, ((option==1) ? 0x00e9ced6 : (option==2) ? 0x00e9ced6 : 0x00157090));
|
|
WPHY_INIT_WRITE_REG(0xf01560, ((option==1) ? 0x00f6b0d3 : (option==2) ? 0x00f6b0d3 : 0x000900cb));
|
|
WPHY_INIT_WRITE_REG(0xf0164c, ((option==1) ? 0x0a09019d : (option==2) ? 0x0a09019d : 0x094803c4));
|
|
WPHY_INIT_WRITE_REG(0xf01634, ((option==1) ? 0x3fb20065 : (option==2) ? 0x3fb20065 : 0x00633fcb));
|
|
WPHY_INIT_WRITE_REG(0xf015b8, ((option==1) ? 0x00d2cd2c : (option==2) ? 0x00d2cd2c : 0x003ff000));
|
|
WPHY_INIT_WRITE_REG(0xf01654, ((option==1) ? 0x003a001d : (option==2) ? 0x003a001d : 0x3fb53fd4));
|
|
WPHY_INIT_WRITE_REG(0xf01564, ((option==1) ? 0x0013512a : (option==2) ? 0x0013612a : 0x00ed7f70));
|
|
WPHY_INIT_WRITE_REG(0xf0165c, ((option==1) ? 0x3f5e3fd0 : (option==2) ? 0x3f5e3fd0 : 0x3fe03fa6));
|
|
WPHY_INIT_WRITE_REG(0xf01424, ((option==1) ? 0x007f2faf : (option==2) ? 0x007f2faf : 0x007f2faf));
|
|
WPHY_INIT_WRITE_REG(0xf01660, ((option==1) ? 0x3f0e3f05 : (option==2) ? 0x3f0e3f05 : 0x00d80047));
|
|
WPHY_INIT_WRITE_REG(0xf01010, ((option==1) ? 0x0040740c : (option==2) ? 0x00203a06 : 0x00101a06));
|
|
WPHY_INIT_WRITE_REG(0xf01664, ((option==1) ? 0x01113fb8 : (option==2) ? 0x01113fb8 : 0x024b018a));
|
|
WPHY_INIT_WRITE_REG(0xf01524, ((option==1) ? 0x0038830f : (option==2) ? 0x00000000 : 0x00000000));
|
|
WPHY_INIT_WRITE_REG(0xf01668, ((option==1) ? 0x04ca02e6 : (option==2) ? 0x04ca02e6 : 0x03a00305));
|
|
WPHY_INIT_WRITE_REG(0xf01414, ((option==1) ? 0x4e2013a9 : (option==2) ? 0x271013a9 : 0x17701798));
|
|
WPHY_INIT_WRITE_REG(0xf01658, ((option==1) ? 0x00240044 : (option==2) ? 0x00240044 : 0x3f923f9c));
|
|
WPHY_INIT_WRITE_REG(0xf0156c, ((option==1) ? 0x00ecb12a : (option==2) ? 0x00eca12a : 0x00129f70));
|
|
WPHY_INIT_WRITE_REG(0xf01318, ((option==1) ? 0x0000015e : (option==2) ? 0x000000fa : 0x000000fa));
|
|
WPHY_INIT_WRITE_REG(0xf0131c, ((option==1) ? 0x004a4a0d : (option==2) ? 0x004a4a0d : 0x004a4a0d));
|
|
WPHY_INIT_WRITE_REG(0xf01304, ((option==1) ? 0x00810000 : (option==2) ? 0x00810000 : 0x00810000));
|
|
WPHY_INIT_WRITE_REG(0xf01404, ((option==1) ? 0x81262111 : (option==2) ? 0x81122111 : 0x82082111));
|
|
WPHY_INIT_WRITE_REG(0xf01570, ((option==1) ? 0x000950d3 : (option==2) ? 0x000950d3 : 0x00f700cb));
|
|
WPHY_INIT_WRITE_REG(0xf01648, ((option==1) ? 0x3d0b3e80 : (option==2) ? 0x3d0b3e80 : 0x3ef43d89));
|
|
WPHY_INIT_WRITE_REG(0xf0141c, ((option==1) ? 0x001503f9 : (option==2) ? 0x001501fd : 0x001500fe));
|
|
WPHY_INIT_WRITE_REG(0xf01574, ((option==1) ? 0x00164ed6 : (option==2) ? 0x00164ed6 : 0x00ea9090));
|
|
WPHY_INIT_WRITE_REG(0xf01228, ((option==1) ? 0x00001424 : (option==2) ? 0x00000a12 : 0x0000060a));
|
|
WPHY_INIT_WRITE_REG(0xf01578, ((option==1) ? 0x000d3f2d : (option==2) ? 0x000d3f2d : 0x00f35000));
|
|
WPHY_INIT_WRITE_REG(0xf0151c, ((option==1) ? 0x001a612d : (option==2) ? 0x0031c239 : 0x003852b1));
|
|
WPHY_INIT_WRITE_REG(0xf01428, ((option==1) ? 0x00fe0407 : (option==2) ? 0x007f080e : 0x0040101b));
|
|
WPHY_INIT_WRITE_REG(0xf01218, ((option==1) ? 0x10601160 : (option==2) ? 0x10601230 : 0x10601212));
|
|
WPHY_INIT_WRITE_REG(0xf0157c, ((option==1) ? 0x00164ed6 : (option==2) ? 0x00164ed6 : 0x00ea9090));
|
|
WPHY_INIT_WRITE_REG(0xf01628, ((option==1) ? 0x00470008 : (option==2) ? 0x00470008 : 0x00043fcb));
|
|
WPHY_INIT_WRITE_REG(0xf01644, ((option==1) ? 0x01580152 : (option==2) ? 0x01580152 : 0x3f0300f3));
|
|
WPHY_INIT_WRITE_REG(0xf01518, ((option==1) ? 0x000b503c : (option==2) ? 0x00155072 : 0x001bf115));
|
|
WPHY_INIT_WRITE_REG(0xf01580, ((option==1) ? 0x000950d3 : (option==2) ? 0x000950d3 : 0x00f700cb));
|
|
WPHY_INIT_WRITE_REG(0xf0122c, ((option==1) ? 0x0080241c : (option==2) ? 0x0040120e : 0x00200a06));
|
|
WPHY_INIT_WRITE_REG(0xf01314, ((option==1) ? 0x00106303 : (option==2) ? 0x00106303 : 0x00106303));
|
|
WPHY_INIT_WRITE_REG(0xf01584, ((option==1) ? 0x00ecb12a : (option==2) ? 0x00eca12a : 0x00129f70));
|
|
WPHY_INIT_WRITE_REG(0xf01120, ((option==1) ? 0x00000008 : (option==2) ? 0x00000004 : 0x00000004));
|
|
WPHY_INIT_WRITE_REG(0xf01124, ((option==1) ? 0x000f0828 : (option==2) ? 0x000f0c14 : 0x000f0c0a));
|
|
WPHY_INIT_WRITE_REG(0xf01128, ((option==1) ? 0x007f3802 : (option==2) ? 0x003f1c02 : 0x001f0c02));
|
|
WPHY_INIT_WRITE_REG(0xf0112c, ((option==1) ? 0x007f5801 : (option==2) ? 0x003f2c01 : 0x001f1401));
|
|
WPHY_INIT_WRITE_REG(0xf01588, ((option==1) ? 0x00000c00 : (option==2) ? 0x00000c00 : 0x00000c00));
|
|
WPHY_INIT_WRITE_REG(0xf01334, ((option==1) ? 0x000000c5 : (option==2) ? 0x000000c5 : 0x000000c5));
|
|
WPHY_INIT_WRITE_REG(0xf01034, ((option==1) ? 0x00000141 : (option==2) ? 0x00000143 : 0x00000145));
|
|
WPHY_INIT_WRITE_REG(0xf0163c, ((option==1) ? 0x001b00dc : (option==2) ? 0x001b00dc : 0x3f2f3f42));
|
|
WPHY_INIT_WRITE_REG(0xf01548, ((option==1) ? 0x00000f2d : (option==2) ? 0x00000f2d : 0x00000e6a));
|
|
WPHY_INIT_WRITE_REG(0xf0158c, ((option==1) ? 0x00d1f2c7 : (option==2) ? 0x00d1f2c7 : 0x0039ae43));
|
|
WPHY_INIT_WRITE_REG(0xf01638, ((option==1) ? 0x00293f61 : (option==2) ? 0x00293f61 : 0x001200a6));
|
|
WPHY_INIT_WRITE_REG(0xf01554, ((option==1) ? 0x00e9ced6 : (option==2) ? 0x00e9ced6 : 0x00157090));
|
|
WPHY_INIT_WRITE_REG(0xf0161c, ((option==1) ? 0x3fd53fdf : (option==2) ? 0x3fd53fdf : 0x3fea3fc8));
|
|
WPHY_INIT_WRITE_REG(0xf0135c, ((option==1) ? 0x00000110 : (option==2) ? 0x00000111 : 0x00000111));
|
|
WPHY_INIT_WRITE_REG(0xf0162c, ((option==1) ? 0x3faa0012 : (option==2) ? 0x3faa0012 : 0x003c0053));
|
|
WPHY_INIT_WRITE_REG(0xf01360, ((option==1) ? 0x00000110 : (option==2) ? 0x00000110 : 0x00000111));
|
|
WPHY_INIT_WRITE_REG(0xf01368, ((option==1) ? 0x00000001 : (option==2) ? 0x00000000 : 0x00000000));
|
|
WPHY_INIT_WRITE_REG(0xf01374, ((option==1) ? 0x00001000 : (option==2) ? 0x00001000 : 0x00001001));
|
|
WPHY_INIT_WRITE_REG(0xf0110c, ((option==1) ? 0x00606060 : (option==2) ? 0x00303030 : 0x00121212));
|
|
WPHY_INIT_WRITE_REG(0xf01378, ((option==1) ? 0x00001000 : (option==2) ? 0x00001001 : 0x00001001));
|
|
WPHY_INIT_WRITE_REG(0xf0154c, ((option==1) ? 0x0013512a : (option==2) ? 0x0013612a : 0x00ed7f70));
|
|
WPHY_INIT_WRITE_REG(0xf01384, ((option==1) ? 0x00000f31 : (option==2) ? 0x00000f31 : 0x00000d11));
|
|
WPHY_INIT_WRITE_REG(0xf0140c, ((option==1) ? 0x80904c4a : (option==2) ? 0x4048264a : 0x2024133a));
|
|
WPHY_INIT_WRITE_REG(0xf01590, ((option==1) ? 0x0024f344 : (option==2) ? 0x0024f344 : 0x00db1344));
|
|
WPHY_INIT_WRITE_REG(0xf01594, ((option==1) ? 0x00311d6f : (option==2) ? 0x00311d6f : 0x00c4f18b));
|
|
WPHY_INIT_WRITE_REG(0xf01598, ((option==1) ? 0x002d4d2c : (option==2) ? 0x002d4d2c : 0x00c00000));
|
|
WPHY_INIT_WRITE_REG(0xf015a4, ((option==1) ? 0x00d1f2c7 : (option==2) ? 0x00d1f2c7 : 0x0039ae43));
|
|
WPHY_INIT_WRITE_REG(0xf0159c, ((option==1) ? 0x00311d6f : (option==2) ? 0x00311d6f : 0x00c4f18b));
|
|
WPHY_INIT_WRITE_REG(0xf015ac, ((option==1) ? 0x002e12c7 : (option==2) ? 0x002e12c7 : 0x00c66e43));
|
|
WPHY_INIT_WRITE_REG(0xf015b0, ((option==1) ? 0x00db1344 : (option==2) ? 0x00db1344 : 0x0024f344));
|
|
WPHY_INIT_WRITE_REG(0xf015b4, ((option==1) ? 0x00cefd6f : (option==2) ? 0x00cefd6f : 0x003b118b));
|
|
WPHY_INIT_WRITE_REG(0xf01230, ((option==1) ? 0x0080140c : (option==2) ? 0x00400a06 : 0x00200602));
|
|
WPHY_INIT_WRITE_REG(0xf01640, ((option==1) ? 0x3f6f3ee5 : (option==2) ? 0x3f6f3ee5 : 0x014f003f));
|
|
WPHY_INIT_WRITE_REG(0xf015bc, ((option==1) ? 0x00cefd6f : (option==2) ? 0x00cefd6f : 0x003b118b));
|
|
WPHY_INIT_WRITE_REG(0xf015c0, ((option==1) ? 0x00db1344 : (option==2) ? 0x00db1344 : 0x0024f344));
|
|
WPHY_INIT_WRITE_REG(0xf015a0, ((option==1) ? 0x0024f344 : (option==2) ? 0x0024f344 : 0x00db1344));
|
|
WPHY_INIT_WRITE_REG(0xf015c4, ((option==1) ? 0x002e12c7 : (option==2) ? 0x002e12c7 : 0x00c66e43));
|
|
WPHY_INIT_WRITE_REG(0xf015c8, ((option==1) ? 0x3ff33ffa : (option==2) ? 0x3ff33ffa : 0x3ffb3ff8));
|
|
WPHY_INIT_WRITE_REG(0xf015cc, ((option==1) ? 0x000e3ffa : (option==2) ? 0x000e3ffa : 0x00160008));
|
|
WPHY_INIT_WRITE_REG(0xf015d0, ((option==1) ? 0x3fec000d : (option==2) ? 0x3fec000d : 0x3fef000e));
|
|
WPHY_INIT_WRITE_REG(0xf015d4, ((option==1) ? 0x00143fe4 : (option==2) ? 0x00143fe4 : 0x3ff73fdb));
|
|
WPHY_INIT_WRITE_REG(0xf01630, ((option==1) ? 0x00593fca : (option==2) ? 0x00593fca : 0x3f853fd8));
|
|
WPHY_INIT_WRITE_REG(0xf015d8, ((option==1) ? 0x3fef002f : (option==2) ? 0x3fef002f : 0x003a002e));
|
|
WPHY_INIT_WRITE_REG(0xf015dc, ((option==1) ? 0x00023fb5 : (option==2) ? 0x00023fb5 : 0x3fa33ff5));
|
|
WPHY_INIT_WRITE_REG(0xf01320, ((option==1) ? 0x62b0a641 : (option==2) ? 0x62b0a641 : 0x62b0a641));
|
|
WPHY_INIT_WRITE_REG(0xf01324, ((option==1) ? 0x061f1f00 : (option==2) ? 0x061f1f00 : 0x061f1f00));
|
|
WPHY_INIT_WRITE_REG(0xf015e0, ((option==1) ? 0x0018006b : (option==2) ? 0x0018006b : 0x003f3fb8));
|
|
WPHY_INIT_WRITE_REG(0xf01550, ((option==1) ? 0x00f6b0d3 : (option==2) ? 0x00f6b0d3 : 0x000900cb));
|
|
WPHY_INIT_WRITE_REG(0xf015e4, ((option==1) ? 0x3fb83f70 : (option==2) ? 0x3fb83f70 : 0x0039009c));
|
|
WPHY_INIT_WRITE_REG(0xf01420, ((option==1) ? 0x00560bec : (option==2) ? 0x00560bec : 0x00560bec));
|
|
WPHY_INIT_WRITE_REG(0xf015e8, ((option==1) ? 0x009300b6 : (option==2) ? 0x009300b6 : 0x3f1a3f5c));
|
|
WPHY_INIT_WRITE_REG(0xf015ec, ((option==1) ? 0x3ef53f23 : (option==2) ? 0x3ef53f23 : 0x0154000f));
|
|
WPHY_INIT_WRITE_REG(0xf01110, ((option==1) ? 0x00001160 : (option==2) ? 0x00001230 : 0x00001212));
|
|
WPHY_INIT_WRITE_REG(0xf01520, ((option==1) ? 0x0029721e : (option==2) ? 0x00000000 : 0x00000000));
|
|
WPHY_INIT_WRITE_REG(0xf015f0, ((option==1) ? 0x01d500fd : (option==2) ? 0x01d500fd : 0x3f1f012a));
|
|
WPHY_INIT_WRITE_REG(0xf015a8, ((option==1) ? 0x00000c00 : (option==2) ? 0x00000c00 : 0x00000c00));
|
|
WPHY_INIT_WRITE_REG(0xf015f4, ((option==1) ? 0x3c773ee7 : (option==2) ? 0x3c773ee7 : 0x3ea33d44));
|
|
WPHY_INIT_WRITE_REG(0xf01620, ((option==1) ? 0x001a0026 : (option==2) ? 0x001a0026 : 0x0026001a));
|
|
WPHY_INIT_WRITE_REG(0xf015f8, ((option==1) ? 0x0b5c0129 : (option==2) ? 0x0b5c0129 : 0x0a87040d));
|
|
WPHY_INIT_WRITE_REG(0xf01650, ((option==1) ? 0x00000e58 : (option==2) ? 0x00000e58 : 0x00000bbe));
|
|
WPHY_INIT_WRITE_REG(0xf015fc, ((option==1) ? 0x000010d0 : (option==2) ? 0x000010d0 : 0x00000d6e));
|
|
WPHY_INIT_WRITE_REG(0xf01528, ((option==1) ? 0x0412000d : (option==2) ? 0x0412000d : 0x0412000d));
|
|
WPHY_INIT_WRITE_REG(0xf0152c, ((option==1) ? 0x0c1d0819 : (option==2) ? 0x0c1d0819 : 0x0c1d0819));
|
|
WPHY_INIT_WRITE_REG(0xf01530, ((option==1) ? 0x0e270d21 : (option==2) ? 0x0e270d21 : 0x0e270d21));
|
|
WPHY_INIT_WRITE_REG(0xf01534, ((option==1) ? 0x00000f2b : (option==2) ? 0x00000f2b : 0x00000f2b));
|
|
|
|
/* set rx threshold */
|
|
bb_rf_set_rx_threshold(((option==1) ? 0x4000 : (option==2) ? 0x4000 : 0x8000));
|
|
|
|
/* if EDA simulation
|
|
* Write(ADDR='h52f0_1000, DATA='h3);
|
|
* Write(ADDR='h52f0_1338, DATA='h0);
|
|
* Write(ADDR='h52f0_1000, DATA='h0);
|
|
* Write(ADDR='hxxf0_1300, DATA='h00110000);
|
|
*/
|
|
|
|
if (HPLC_RF_RX_BPF_EN && rf_ver == RF_VER_3) {
|
|
WPHY_INIT_WRITE_REG(0xf01340, ((option == PHY_RF_OPTION1_1M) ? 0 : (option == PHY_RF_OPTION2_500K) ? 9438 : 3774));
|
|
} else {
|
|
WPHY_INIT_WRITE_REG(0xf01340, ((option == PHY_RF_OPTION1_1M) ? 0 : (option == PHY_RF_OPTION2_500K) ? 6291 : 3146));
|
|
}
|
|
/* scphase table config */
|
|
for (i = 0; i < 16*2; i++) {
|
|
WPHY_WRITE_MEM_SCPHASE(i, phy_rf_scphase_table[option - 1][i]);
|
|
}
|
|
|
|
/* scidx table config */
|
|
for (i = 0; i < 32*8; i++) {
|
|
WPHY_WRITE_MEM_SCIDX(i, phy_rf_scidx_table[option - 1][i]);
|
|
}
|
|
|
|
/* rf dc clibration */
|
|
bb_rf_clibr_dc(option);
|
|
}
|
|
|
|
void bb_rf_tx_reset()
|
|
{
|
|
uint32_t tmp = WPHY_READ_REG(WPHY_CODEC_SRST_CFG_ADDR);
|
|
REG_FIELD_SET(CODEC_TX_SRST_L, tmp, 0);
|
|
WPHY_WRITE_REG(WPHY_PHR_BASIC_CFG_ADDR, tmp);
|
|
|
|
tmp = WPHY_READ_REG(WPHY_MODEM_SRST_CFG_ADDR);
|
|
REG_FIELD_SET(MODEM_TX_SRST_L, tmp, 0);
|
|
WPHY_WRITE_REG(WPHY_MODEM_SRST_CFG_ADDR, tmp);
|
|
|
|
tmp = WPHY_READ_REG(WPHY_CODEC_SRST_CFG_ADDR);
|
|
REG_FIELD_SET(CODEC_TX_SRST_L, tmp, 1);
|
|
WPHY_WRITE_REG(WPHY_PHR_BASIC_CFG_ADDR, tmp);
|
|
|
|
tmp = WPHY_READ_REG(WPHY_MODEM_SRST_CFG_ADDR);
|
|
REG_FIELD_SET(MODEM_TX_SRST_L, tmp, 1);
|
|
WPHY_WRITE_REG(WPHY_MODEM_SRST_CFG_ADDR, tmp);
|
|
}
|
|
|
|
void bb_rf_rx_reset()
|
|
{
|
|
uint32_t tmp = WPHY_READ_REG(WPHY_CODEC_SRST_CFG_ADDR);
|
|
REG_FIELD_SET(CODEC_RX_SRST_L, tmp, 0);
|
|
WPHY_WRITE_REG(WPHY_PHR_BASIC_CFG_ADDR, tmp);
|
|
|
|
tmp = WPHY_READ_REG(WPHY_MODEM_SRST_CFG_ADDR);
|
|
REG_FIELD_SET(MODEM_RX_SRST_L, tmp, 0);
|
|
WPHY_WRITE_REG(WPHY_MODEM_SRST_CFG_ADDR, tmp);
|
|
|
|
tmp = WPHY_READ_REG(WPHY_CODEC_SRST_CFG_ADDR);
|
|
REG_FIELD_SET(CODEC_RX_SRST_L, tmp, 1);
|
|
WPHY_WRITE_REG(WPHY_PHR_BASIC_CFG_ADDR, tmp);
|
|
|
|
tmp = WPHY_READ_REG(WPHY_MODEM_SRST_CFG_ADDR);
|
|
REG_FIELD_SET(MODEM_RX_SRST_L, tmp, 1);
|
|
WPHY_WRITE_REG(WPHY_MODEM_SRST_CFG_ADDR, tmp);
|
|
}
|
|
|
|
void bb_rf_jesd_reset()
|
|
{
|
|
uint16_t init;
|
|
/* R0 reg bit 1, write 0 and write 1 */
|
|
|
|
init = rf_spi_read(0);
|
|
|
|
/* write 0 */
|
|
init &= 0xfffd;
|
|
rf_spi_write(0, init);
|
|
|
|
/* write 1 */
|
|
init |= 0x2;
|
|
rf_spi_write(0, init);
|
|
}
|
|
|
|
|
|
void bb_rf_reset()
|
|
{
|
|
bb_rf_tx_reset();
|
|
bb_rf_rx_reset();
|
|
bb_rf_jesd_reset();
|
|
}
|
|
|
|
void bb_rf_set_rx_threshold(uint32_t threshold)
|
|
{
|
|
/* The recommended step is 1000 */
|
|
WPHY_INIT_WRITE_REG(0xf01400, threshold); // Frame Sync threshold
|
|
}
|
|
|
|
uint32_t bb_wphy_read_fld_reg(uint32_t addr, uint32_t bit_start,
|
|
uint32_t bit_end)
|
|
{
|
|
uint32_t mask = 0;
|
|
uint32_t bitnum = bit_end - bit_start + 1;
|
|
IOT_ASSERT(bitnum <= 32);
|
|
if (bitnum == 32) {
|
|
mask = 0xFFFFFFFF;
|
|
} else {
|
|
mask = ((1 << bitnum) - 1) << bit_start;
|
|
}
|
|
|
|
uint32_t tmp = WPHY_INIT_READ_REG(addr);
|
|
uint32_t value = (tmp & mask) >> bit_start;
|
|
return value;
|
|
}
|
|
|
|
void bb_wphy_write_fld_reg(uint32_t addr, uint32_t bit_start,
|
|
uint32_t bit_end, uint32_t value)
|
|
{
|
|
uint32_t mask = 0;
|
|
uint32_t bitnum = bit_end - bit_start + 1;
|
|
IOT_ASSERT(bitnum <= 32);
|
|
if (bitnum == 32) {
|
|
mask = 0xFFFFFFFF;
|
|
} else {
|
|
mask = ((1 << bitnum) - 1) << bit_start;
|
|
}
|
|
|
|
uint32_t tmp = WPHY_INIT_READ_REG(addr);
|
|
tmp &= ~mask;
|
|
tmp |= (value << bit_start) & mask;
|
|
WPHY_INIT_WRITE_REG(addr, tmp);
|
|
}
|
|
|
|
void bb_wphy_stop_rx(void)
|
|
{
|
|
if (bb_wphy_read_fld_reg(0xf013a4, 3, 3) ||
|
|
bb_wphy_read_fld_reg(0xf013a4, 2, 2)) {
|
|
bb_wphy_write_fld_reg(0xf01200, 3, 3, 1);
|
|
bb_rf_rx_reset();
|
|
}
|
|
bb_wphy_write_fld_reg(0xf0120c, 0, 15, 0xffff);
|
|
bb_rf_jesd_reset();
|
|
bb_rf_pll_cfg();
|
|
}
|
|
|
|
void bb_wphy_stop_tx(void)
|
|
{
|
|
if (bb_wphy_read_fld_reg(0xf01398, 3, 3) ||
|
|
bb_wphy_read_fld_reg(0xf01398, 2, 2)) {
|
|
bb_wphy_write_fld_reg(0xf01108, 2, 2, 1);
|
|
}
|
|
bb_rf_tx_reset();
|
|
bb_rf_jesd_reset();
|
|
bb_rf_pll_cfg();
|
|
}
|
|
|