1 /*
2  * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 #include "esp_phy_init.h"
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #define ESP_CAL_DATA_CHECK_FAIL 1
15 
16 /**
17  * @file phy.h
18  * @brief Declarations for functions provided by libphy.a
19  */
20 
21 /**
22  * @brief Return ROM function pointer table from PHY library.
23  */
24 void phy_get_romfunc_addr(void);
25 
26 /**
27  * @brief Initialize PHY module and do RF calibration
28  * @param[in] init_data Initialization parameters to be used by the PHY
29  * @param[inout] cal_data As input, calibration data previously obtained. As output, will contain new calibration data.
30  * @param[in] cal_mode  RF calibration mode
31  * @return ESP_CAL_DATA_CHECK_FAIL if calibration data checksum fails, other values are reserved for future use
32  */
33 int register_chipv7_phy(const esp_phy_init_data_t* init_data, esp_phy_calibration_data_t *cal_data, esp_phy_calibration_mode_t cal_mode);
34 
35 /**
36  * @brief Get the format version of calibration data used by PHY library.
37  * @return Format version number, OR'ed with BIT(16) if PHY is in WIFI only mode.
38  */
39 uint32_t phy_get_rf_cal_version(void);
40 
41 /**
42  * @brief Set RF/BB for only WIFI mode or coexist(WIFI & BT) mode
43  * @param[in] true is for only WIFI mode, false is for coexist mode. default is 0.
44  * @return NULL
45  */
46 void phy_set_wifi_mode_only(bool wifi_only);
47 
48 /**
49  * @brief Set BT the highest priority in coexist mode.
50  * @return NULL
51  */
52 void coex_bt_high_prio(void);
53 
54 /**
55  * @brief Open PHY and RF.
56  */
57 void phy_wakeup_init(void);
58 
59 /**
60  * @brief Shutdown PHY and RF.
61  */
62 void phy_close_rf(void);
63 
64 #if !CONFIG_IDF_TARGET_ESP32
65 /**
66  * @brief Disable PHY temperature sensor.
67  */
68 void phy_xpd_tsens(void);
69 #endif
70 
71 #if CONFIG_IDF_TARGET_ESP32C3
72 /**
73  * @brief Update internal state of PHY when wifi deinit powers off the wifi power domain.
74  */
75 void phy_init_flag(void);
76 #endif
77 
78 /**
79  * @brief Store and load PHY digital registers.
80  *
81  * @param     backup_en  if backup_en is true, store PHY digital registers to memory. Otherwise load PHY digital registers from memory
82  * @param     mem_addr   Memory address to store and load PHY digital registers
83  *
84  * @return    memory size
85  */
86 uint8_t phy_dig_reg_backup(bool backup_en, uint32_t *mem_addr);
87 
88 #if CONFIG_MAC_BB_PD
89 /**
90  * @brief Store and load baseband registers.
91  */
92 void phy_freq_mem_backup(bool backup_en, uint32_t *mem);
93 #endif
94 
95 #if CONFIG_SERIAL_ESP32_USB
96 /**
97  * @brief Enable or disable USB when phy init.
98  */
99 void phy_bbpll_en_usb(bool en);
100 #endif
101 
102 #if CONFIG_IDF_TARGET_ESP32S2
103 /**
104  * @brief Phy version select for ESP32S2
105  */
106 void phy_eco_version_sel(uint8_t chip_ver);
107 #endif
108 
109 #ifdef __cplusplus
110 }
111 #endif
112