1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2017 NXP 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * o Redistributions of source code must retain the above copyright notice, this list 9 * of conditions and the following disclaimer. 10 * 11 * o Redistributions in binary form must reproduce the above copyright notice, this 12 * list of conditions and the following disclaimer in the documentation and/or 13 * other materials provided with the distribution. 14 * 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its 16 * contributors may be used to endorse or promote products derived from this 17 * software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 #ifndef __IFR_RADIO_H__ 31 /* clang-format off */ 32 #define __IFR_RADIO_H__ 33 /* clang-format on */ 34 35 #include <stdint.h> 36 /* clang-format off */ 37 #define _FSL_XCVR_H_ 38 /* clang-format on */ 39 40 /*! 41 * @addtogroup xcvr 42 * @{ 43 */ 44 45 /*! @file*/ 46 47 /******************************************************************************* 48 * Definitions 49 ******************************************************************************/ 50 #define IFR_EOF_SYMBOL (0xFEED0E0FU) /* < Denotes the "End of File" for IFR data */ 51 #define IFR_VERSION_HDR (0xABCD0000U) /* < Constant value for upper 16 bits of IFR data header */ 52 #define IFR_VERSION_MASK (0x0000FFFFU) /* < Mask for version number (lower 16 bits) of IFR data header */ 53 #define IFR_SW_ID_MIN (0x00000000U) /* < Lower limit of SW trim IDs */ 54 #define IFR_SW_ID_MAX (0x0000FFFFU) /* < Lower limit of SW trim IDs */ 55 56 #define IS_A_SW_ID(x) ((IFR_SW_ID_MIN < (x)) && (IFR_SW_ID_MAX >= (x))) 57 58 /* K3 valid registers support */ 59 #if (defined(CPU_K32W042S1M2CAx_M0P) || defined(CPU_K32W042S1M2VPJ_M0P)) 60 #define IS_VALID_REG_ADDR(x) (((x) & 0xFFFF0000U) == 0x41000000U) /* Valid addresses are 0x410xxxxx */ 61 #endif /* (defined(CPU_K32W042S1M2CAx_M0P) || defined(CPU_K32W042S1M2VPJ_M0P)) */ 62 /* KW41 and KW35/36 valid registers support */ 63 #if (defined(CPU_MKW41Z256VHT4) || defined(CPU_MKW41Z512VHT4) || \ 64 defined(CPU_MKW31Z256VHT4) || defined(CPU_MKW31Z512VHT4) || \ 65 defined(CPU_MKW21Z256VHT4) || defined(CPU_MKW21Z512VHT4) || \ 66 defined(CPU_MKW35A512VFP4) || defined(CPU_MKW36A512VFP4) ) 67 68 #define IS_VALID_REG_ADDR(x) (((x) & 0xFFFF0000U) == 0x40050000U) /* Valid addresses are 0x4005xxxx */ 69 #endif 70 71 #define MAKE_MASK(size) ((1 << (size)) - 1) 72 #define MAKE_MASKSHFT(size, bitpos) (MAKE_MASK(size) << (bitpos)) 73 74 #define IFR_TZA_CAP_TUNE_MASK (0x0000000FU) 75 #define IFR_TZA_CAP_TUNE_SHIFT (0) 76 #define IFR_BBF_CAP_TUNE_MASK (0x000F0000U) 77 #define IFR_BBF_CAP_TUNE_SHIFT (16) 78 #define IFR_RES_TUNE2_MASK (0x00F00000U) 79 #define IFR_RES_TUNE2_SHIFT (20) 80 81 /* \var typedef uint8_t IFR_ERROR_T */ 82 /* \brief The IFR error reporting type. */ 83 /* See #IFR_ERROR_T_enum for the enumeration definitions. */ 84 typedef uint8_t IFR_ERROR_T; 85 86 /* \brief The enumerations used to describe IFR errors. */ 87 enum IFR_ERROR_T_enum 88 { 89 IFR_SUCCESS = 0, 90 INVALID_POINTER = 1, /* < NULL pointer error */ 91 INVALID_DEST_SIZE_SHIFT = 2, /* < the bits won't fit as specified in the destination */ 92 }; 93 94 /* \var typedef uint16_t SW_TRIM_ID_T */ 95 /* \brief The SW trim ID type. */ 96 /* See #SW_TRIM_ID_T_enum for the enumeration definitions. */ 97 typedef uint16_t SW_TRIM_ID_T; 98 99 /* \brief The enumerations used to define SW trim IDs. */ 100 enum SW_TRIM_ID_T_enum 101 { 102 Q_RELATIVE_GAIN_BY_PART = 0, /* < Q vs I relative gain trim ID */ 103 ADC_GAIN = 1, /* < ADC gain trim ID */ 104 ZB_FILT_TRIM = 2, /* < Baseband Bandwidth filter trim ID for BLE */ 105 BLE_FILT_TRIM = 3, /* < Baseband Bandwidth filter trim ID for BLE */ 106 TRIM_STATUS = 4, /* < Status result of the trim process (error indications) */ 107 TRIM_VERSION = 0xABCD, /* < Version number of the IFR trim algorithm/format. */ 108 }; 109 110 /* \var typedef uint32_t IFR_TRIM_STATUS_T */ 111 /* \brief The definition of failure bits stored in IFR trim status word. */ 112 /* See #IFR_TRIM_STATUS_T_enum for the enumeration definitions. */ 113 typedef uint32_t IFR_TRIM_STATUS_T; 114 115 /* \brief The enumerations used to describe trim algorithm failures in the status entry in IFR. */ 116 /* This enum represents multiple values which can be OR'd together in a single status word. */ 117 enum IFR_TRIM_STATUS_T_enum 118 { 119 TRIM_ALGORITHM_SUCCESS = 0, 120 BGAP_VOLTAGE_TRIM_FAILED = 1, /* < algorithm failure in BGAP voltagetrim */ 121 IQMC_GAIN_ADJ_FAILED = 2, /* < algorithm failure in IQMC gain trim */ 122 IQMC_PHASE_ADJ_FAILED = 4, /* < algorithm failure in IQMC phase trim */ 123 IQMC_DC_GAIN_ADJ_FAILED = 8, /* < */ 124 ADC_GAIN_TRIM_FAILED = 10, /* <*/ 125 ZB_FILT_TRIM_FAILED = 20, /* < */ 126 BLE_FILT_TRIM_FAILED = 40, /* < */ 127 }; 128 129 /* \var typedef struct IFR_SW_TRIM_TBL_ENTRY_T */ 130 /* \brief Structure defining an entry in a table used to contain values to be passed back from IFR */ 131 /* handling routine to XCVR driver software. */ 132 typedef struct 133 { 134 SW_TRIM_ID_T trim_id; /* < The assigned ID */ 135 uint32_t trim_value; /* < The value fetched from IFR.*/ 136 uint8_t valid; /* < validity of the trim_value field after IFR processing is complete (TRUE/FALSE).*/ 137 } IFR_SW_TRIM_TBL_ENTRY_T; 138 139 /******************************************************************************* 140 * API 141 ******************************************************************************/ 142 /*! 143 * @brief Reads a location in block 1 IFR for use by the radio. 144 * 145 * This function handles reading IFR data from flash memory for trim loading. 146 * 147 * @param read_addr the address in the IFR to be read. 148 */ 149 uint32_t read_resource_ifr(uint32_t read_addr); 150 151 /*! 152 * @brief Reads a location in a simulated data array to support IFR handler testing. 153 * 154 * This function handles reading data from a const table for testing the trim loading functions. 155 * 156 * @param read_addr the address in the IFR to be read. 157 */ 158 uint32_t read_resource(uint16_t resource_id); 159 160 /*! 161 * @brief Main IFR handler function called by XCVR driver software to process trim table. 162 * 163 * This function handles reading data from IFR and either loading to registers or storing to a SW trim values table. 164 * 165 * @param sw_trim_tbl pointer to the table used to store software trim values. 166 * @param num_entries the number of entries that can be stored in the SW trim table. 167 */ 168 void handle_ifr(IFR_SW_TRIM_TBL_ENTRY_T * sw_trim_tbl, uint16_t num_entries); 169 170 /*! 171 * @brief Handler function to read die_id from IFR locations.. 172 * 173 * This function handles reading die ID value for debug and testing usage. 174 * 175 * @return the value of the die ID field. 176 */ 177 uint32_t handle_ifr_die_id(void); 178 179 /*! 180 * @brief Handler function to read KW chip version from IFR locations.. 181 * 182 * This function handles reading KW chip version for debug and testing usage. 183 * 184 * @return the value of the KW version field. 185 */ 186 uint32_t handle_ifr_die_kw_type(void); 187 188 /*! 189 * @brief Debug function to dump the IFR contents to a RAM array. 190 * 191 * This function handles reading data from IFR and storing to a RAM array for debug. 192 * 193 * @param dump_tbl pointer to the table used to store IFR entry values. 194 * @param num_entries the number of entries that can be stored in the dump table. 195 */ 196 void dump_ifr(uint32_t * dump_tbl, uint8_t num_entries); 197 198 #endif /*__IFR_RADIO_H__ */ 199 200