|
| 1 | +/* |
| 2 | + Copyright(c) 2021 Intel Corporation |
| 3 | + All rights reserved. |
| 4 | +
|
| 5 | + This program is free software; you can redistribute it and/or modify |
| 6 | + it under the terms of version 2 of the GNU General Public License as |
| 7 | + published by the Free Software Foundation. |
| 8 | +
|
| 9 | + This program is distributed in the hope that it will be useful, but |
| 10 | + WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | + General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with this program; if not, write to the Free Software |
| 16 | + Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | + The full GNU General Public License is included in this distribution |
| 18 | + in the file called LICENSE.GPL. |
| 19 | +*/ |
| 20 | + |
| 21 | +#ifndef __DMIC_MACROS_H |
| 22 | +#define __DMIC_MACROS_H |
| 23 | + |
| 24 | +/* Get max and min signed integer values for N bits word length */ |
| 25 | +#define INT_MAX(N) ((int64_t)((1ULL << ((N) - 1)) - 1)) |
| 26 | + |
| 27 | +/* Fractional multiplication with shift and round |
| 28 | + * Note that the parameters px and py must be cast to (int64_t) if other type. |
| 29 | + */ |
| 30 | +#define Q_MULTSR_32X32(px, py, qx, qy, qp) \ |
| 31 | + ((((px) * (py) >> ((qx) + (qy) - (qp) - 1)) + 1) >> 1) |
| 32 | + |
| 33 | +/* Convert a float number to fractional Qnx.ny format. Note that there is no |
| 34 | + * check for nx+ny number of bits to fit the word length of int. The parameter |
| 35 | + * qy must be 31 or less. |
| 36 | + */ |
| 37 | +#define Q_CONVERT_FLOAT(f, qy) \ |
| 38 | + ((int32_t)(((const double)f) * ((int64_t)1 << (const int)qy) + 0.5)) |
| 39 | + |
| 40 | +/* Saturation */ |
| 41 | +#define SATP_INT32(x) (((x) > INT32_MAX) ? INT32_MAX : (x)) |
| 42 | + |
| 43 | +#define EXP_FIXED_INPUT_QY 27 |
| 44 | +#define EXP_FIXED_OUTPUT_QY 20 |
| 45 | +#define DB2LIN_FIXED_INPUT_QY 24 |
| 46 | +#define DB2LIN_FIXED_OUTPUT_QY 20 |
| 47 | + |
| 48 | +#define DMIC_MAX_MODES 50 |
| 49 | +#define DMIC_FIR_PIPELINE_OVERHEAD 5 |
| 50 | +#define DMIC_UNMUTE_RAMP_US 1000 |
| 51 | + |
| 52 | +/* Parameters used in modes computation */ |
| 53 | +#define DMIC_HW_BITS_CIC 26 |
| 54 | +#define DMIC_HW_BITS_FIR_COEF 20 |
| 55 | +#define DMIC_HW_BITS_FIR_GAIN 20 |
| 56 | +#define DMIC_HW_BITS_FIR_INPUT 22 |
| 57 | +#define DMIC_HW_BITS_FIR_OUTPUT 24 |
| 58 | +#define DMIC_HW_BITS_FIR_INTERNAL 26 |
| 59 | +#define DMIC_HW_BITS_GAIN_OUTPUT 22 |
| 60 | +#define DMIC_HW_CIC_SHIFT_MIN -8 |
| 61 | +#define DMIC_HW_CIC_SHIFT_MAX 4 |
| 62 | +#define DMIC_HW_FIR_SHIFT_MIN 0 |
| 63 | +#define DMIC_HW_FIR_SHIFT_MAX 8 |
| 64 | +#define DMIC_HW_CIC_DECIM_MIN 5 |
| 65 | +#define DMIC_HW_CIC_DECIM_MAX 31 /* Note: Limited by BITS_CIC */ |
| 66 | +#define DMIC_HW_FIR_DECIM_MIN 2 |
| 67 | +#define DMIC_HW_FIR_DECIM_MAX 20 /* Note: Practical upper limit */ |
| 68 | +#define DMIC_HW_SENS_Q28 Q_CONVERT_FLOAT(1.0, 28) /* Q1.28 */ |
| 69 | +#define DMIC_HW_PDM_CLK_MIN 100000 /* Note: Practical min value */ |
| 70 | +#define DMIC_HW_DUTY_MIN 20 /* Note: Practical min value */ |
| 71 | +#define DMIC_HW_DUTY_MAX 80 /* Note: Practical max value */ |
| 72 | + |
| 73 | +/* OUTCONTROL0 bits */ |
| 74 | +#define OUTCONTROL0_TIE_BIT BIT(27) |
| 75 | +#define OUTCONTROL0_SIP_BIT BIT(26) |
| 76 | +#define OUTCONTROL0_FINIT_BIT BIT(25) |
| 77 | +#define OUTCONTROL0_FCI_BIT BIT(24) |
| 78 | +#define OUTCONTROL0_TIE(x) SET_BIT(27, x) |
| 79 | +#define OUTCONTROL0_SIP(x) SET_BIT(26, x) |
| 80 | +#define OUTCONTROL0_FINIT(x) SET_BIT(25, x) |
| 81 | +#define OUTCONTROL0_FCI(x) SET_BIT(24, x) |
| 82 | +#define OUTCONTROL0_BFTH(x) SET_BITS(23, 20, x) |
| 83 | +#define OUTCONTROL0_OF(x) SET_BITS(19, 18, x) |
| 84 | +#define OUTCONTROL0_TH(x) SET_BITS(5, 0, x) |
| 85 | + |
| 86 | +/* OUTCONTROL1 bits */ |
| 87 | +#define OUTCONTROL1_TIE_BIT BIT(27) |
| 88 | +#define OUTCONTROL1_SIP_BIT BIT(26) |
| 89 | +#define OUTCONTROL1_FINIT_BIT BIT(25) |
| 90 | +#define OUTCONTROL1_FCI_BIT BIT(24) |
| 91 | +#define OUTCONTROL1_TIE(x) SET_BIT(27, x) |
| 92 | +#define OUTCONTROL1_SIP(x) SET_BIT(26, x) |
| 93 | +#define OUTCONTROL1_FINIT(x) SET_BIT(25, x) |
| 94 | +#define OUTCONTROL1_FCI(x) SET_BIT(24, x) |
| 95 | +#define OUTCONTROL1_BFTH(x) SET_BITS(23, 20, x) |
| 96 | +#define OUTCONTROL1_OF(x) SET_BITS(19, 18, x) |
| 97 | +#define OUTCONTROL1_TH(x) SET_BITS(5, 0, x) |
| 98 | + |
| 99 | +/* OUTCONTROL0 bits ver1*/ |
| 100 | +#define OUTCONTROL0_IPM_VER1(x) SET_BITS(17, 16, x) |
| 101 | +/* OUTCONTROL1 bits ver1 */ |
| 102 | +#define OUTCONTROL1_IPM_VER1(x) SET_BITS(17, 16, x) |
| 103 | + |
| 104 | +/* OUTCONTROL0 bits */ |
| 105 | +#define OUTCONTROL0_IPM_VER2(x) SET_BITS(17, 15, x) |
| 106 | +#define OUTCONTROL0_IPM_SOURCE_1(x) SET_BITS(14, 13, x) |
| 107 | +#define OUTCONTROL0_IPM_SOURCE_2(x) SET_BITS(12, 11, x) |
| 108 | +#define OUTCONTROL0_IPM_SOURCE_3(x) SET_BITS(10, 9, x) |
| 109 | +#define OUTCONTROL0_IPM_SOURCE_4(x) SET_BITS(8, 7, x) |
| 110 | + |
| 111 | +/* OUTCONTROL1 bits */ |
| 112 | +#define OUTCONTROL1_IPM_VER2(x) SET_BITS(17, 15, x) |
| 113 | +#define OUTCONTROL1_IPM_SOURCE_1(x) SET_BITS(14, 13, x) |
| 114 | +#define OUTCONTROL1_IPM_SOURCE_2(x) SET_BITS(12, 11, x) |
| 115 | +#define OUTCONTROL1_IPM_SOURCE_3(x) SET_BITS(10, 9, x) |
| 116 | +#define OUTCONTROL1_IPM_SOURCE_4(x) SET_BITS(8, 7, x) |
| 117 | + |
| 118 | +#define OUTCONTROLX_IPM_NUMSOURCES 4 |
| 119 | + |
| 120 | +/* CIC_CONTROL bits */ |
| 121 | +#define CIC_CONTROL_SOFT_RESET_BIT BIT(16) |
| 122 | +#define CIC_CONTROL_CIC_START_B_BIT BIT(15) |
| 123 | +#define CIC_CONTROL_CIC_START_A_BIT BIT(14) |
| 124 | +#define CIC_CONTROL_MIC_B_POLARITY_BIT BIT(3) |
| 125 | +#define CIC_CONTROL_MIC_A_POLARITY_BIT BIT(2) |
| 126 | +#define CIC_CONTROL_MIC_MUTE_BIT BIT(1) |
| 127 | +#define CIC_CONTROL_STEREO_MODE_BIT BIT(0) |
| 128 | + |
| 129 | +#define CIC_CONTROL_SOFT_RESET(x) SET_BIT(16, x) |
| 130 | +#define CIC_CONTROL_CIC_START_B(x) SET_BIT(15, x) |
| 131 | +#define CIC_CONTROL_CIC_START_A(x) SET_BIT(14, x) |
| 132 | +#define CIC_CONTROL_MIC_B_POLARITY(x) SET_BIT(3, x) |
| 133 | +#define CIC_CONTROL_MIC_A_POLARITY(x) SET_BIT(2, x) |
| 134 | +#define CIC_CONTROL_MIC_MUTE(x) SET_BIT(1, x) |
| 135 | +#define CIC_CONTROL_STEREO_MODE(x) SET_BIT(0, x) |
| 136 | + |
| 137 | +/* CIC_CONFIG bits */ |
| 138 | +#define CIC_CONFIG_CIC_SHIFT(x) SET_BITS(27, 24, x) |
| 139 | +#define CIC_CONFIG_COMB_COUNT(x) SET_BITS(15, 8, x) |
| 140 | + |
| 141 | +/* CIC_CONFIG masks */ |
| 142 | +#define CIC_CONFIG_CIC_SHIFT_MASK MASK(27, 24) |
| 143 | +#define CIC_CONFIG_COMB_COUNT_MASK MASK(15, 8) |
| 144 | + |
| 145 | +/* MIC_CONTROL bits */ |
| 146 | +#define MIC_CONTROL_PDM_EN_B_BIT BIT(1) |
| 147 | +#define MIC_CONTROL_PDM_EN_A_BIT BIT(0) |
| 148 | +#define MIC_CONTROL_PDM_CLKDIV(x) SET_BITS(15, 8, x) |
| 149 | +#define MIC_CONTROL_PDM_SKEW(x) SET_BITS(7, 4, x) |
| 150 | +#define MIC_CONTROL_CLK_EDGE(x) SET_BIT(3, x) |
| 151 | +#define MIC_CONTROL_PDM_EN_B(x) SET_BIT(1, x) |
| 152 | +#define MIC_CONTROL_PDM_EN_A(x) SET_BIT(0, x) |
| 153 | + |
| 154 | +/* MIC_CONTROL masks */ |
| 155 | +#define MIC_CONTROL_PDM_CLKDIV_MASK MASK(15, 8) |
| 156 | + |
| 157 | +/* FIR_CONTROL_A bits */ |
| 158 | +#define FIR_CONTROL_A_START_BIT BIT(7) |
| 159 | +#define FIR_CONTROL_A_ARRAY_START_EN_BIT BIT(6) |
| 160 | +#define FIR_CONTROL_A_MUTE_BIT BIT(1) |
| 161 | +#define FIR_CONTROL_A_START(x) SET_BIT(7, x) |
| 162 | +#define FIR_CONTROL_A_ARRAY_START_EN(x) SET_BIT(6, x) |
| 163 | +#define FIR_CONTROL_A_DCCOMP(x) SET_BIT(4, x) |
| 164 | +#define FIR_CONTROL_A_MUTE(x) SET_BIT(1, x) |
| 165 | +#define FIR_CONTROL_A_STEREO(x) SET_BIT(0, x) |
| 166 | + |
| 167 | +/* FIR_CONFIG_A bits */ |
| 168 | +#define FIR_CONFIG_A_FIR_DECIMATION(x) SET_BITS(20, 16, x) |
| 169 | +#define FIR_CONFIG_A_FIR_SHIFT(x) SET_BITS(11, 8, x) |
| 170 | +#define FIR_CONFIG_A_FIR_LENGTH(x) SET_BITS(7, 0, x) |
| 171 | + |
| 172 | +/* DC offset compensation time constants */ |
| 173 | +#define DCCOMP_TC0 0 |
| 174 | +#define DCCOMP_TC1 1 |
| 175 | +#define DCCOMP_TC2 2 |
| 176 | +#define DCCOMP_TC3 3 |
| 177 | +#define DCCOMP_TC4 4 |
| 178 | +#define DCCOMP_TC5 5 |
| 179 | +#define DCCOMP_TC6 6 |
| 180 | +#define DCCOMP_TC7 7 |
| 181 | + |
| 182 | +/* DC_OFFSET_LEFT_A bits */ |
| 183 | +#define DC_OFFSET_LEFT_A_DC_OFFS(x) SET_BITS(21, 0, x) |
| 184 | + |
| 185 | +/* DC_OFFSET_RIGHT_A bits */ |
| 186 | +#define DC_OFFSET_RIGHT_A_DC_OFFS(x) SET_BITS(21, 0, x) |
| 187 | + |
| 188 | +/* OUT_GAIN_LEFT_A bits */ |
| 189 | +#define OUT_GAIN_LEFT_A_GAIN(x) SET_BITS(19, 0, x) |
| 190 | + |
| 191 | +/* OUT_GAIN_RIGHT_A bits */ |
| 192 | +#define OUT_GAIN_RIGHT_A_GAIN(x) SET_BITS(19, 0, x) |
| 193 | + |
| 194 | +/* FIR_CONTROL_B bits */ |
| 195 | +#define FIR_CONTROL_B_START_BIT BIT(7) |
| 196 | +#define FIR_CONTROL_B_ARRAY_START_EN_BIT BIT(6) |
| 197 | +#define FIR_CONTROL_B_MUTE_BIT BIT(1) |
| 198 | +#define FIR_CONTROL_B_START(x) SET_BIT(7, x) |
| 199 | +#define FIR_CONTROL_B_ARRAY_START_EN(x) SET_BIT(6, x) |
| 200 | +#define FIR_CONTROL_B_DCCOMP(x) SET_BIT(4, x) |
| 201 | +#define FIR_CONTROL_B_MUTE(x) SET_BIT(1, x) |
| 202 | +#define FIR_CONTROL_B_STEREO(x) SET_BIT(0, x) |
| 203 | + |
| 204 | +/* FIR_CONFIG_B bits */ |
| 205 | +#define FIR_CONFIG_B_FIR_DECIMATION(x) SET_BITS(20, 16, x) |
| 206 | +#define FIR_CONFIG_B_FIR_SHIFT(x) SET_BITS(11, 8, x) |
| 207 | +#define FIR_CONFIG_B_FIR_LENGTH(x) SET_BITS(7, 0, x) |
| 208 | + |
| 209 | +/* DC_OFFSET_LEFT_B bits */ |
| 210 | +#define DC_OFFSET_LEFT_B_DC_OFFS(x) SET_BITS(21, 0, x) |
| 211 | + |
| 212 | +/* DC_OFFSET_RIGHT_B bits */ |
| 213 | +#define DC_OFFSET_RIGHT_B_DC_OFFS(x) SET_BITS(21, 0, x) |
| 214 | + |
| 215 | +/* OUT_GAIN_LEFT_B bits */ |
| 216 | +#define OUT_GAIN_LEFT_B_GAIN(x) SET_BITS(19, 0, x) |
| 217 | + |
| 218 | +/* OUT_GAIN_RIGHT_B bits */ |
| 219 | +#define OUT_GAIN_RIGHT_B_GAIN(x) SET_BITS(19, 0, x) |
| 220 | + |
| 221 | +/* FIR coefficients */ |
| 222 | +#define FIR_COEF_A(x) SET_BITS(19, 0, x) |
| 223 | +#define FIR_COEF_B(x) SET_BITS(19, 0, x) |
| 224 | + |
| 225 | +/* Minimum OSR is always applied for 48 kHz and less sample rates */ |
| 226 | +#define DMIC_MIN_OSR 50 |
| 227 | + |
| 228 | +/* These are used as guideline for configuring > 48 kHz sample rates. The |
| 229 | + * minimum OSR can be relaxed down to 40 (use 3.84 MHz clock for 96 kHz). |
| 230 | + */ |
| 231 | +#define DMIC_HIGH_RATE_MIN_FS 64000 |
| 232 | +#define DMIC_HIGH_RATE_OSR_MIN 40 |
| 233 | + |
| 234 | +/* Used for scaling FIR coefficients for HW */ |
| 235 | +#define DMIC_HW_FIR_COEF_MAX ((1 << (DMIC_HW_BITS_FIR_COEF - 1)) - 1) |
| 236 | +#define DMIC_HW_FIR_COEF_Q (DMIC_HW_BITS_FIR_COEF - 1) |
| 237 | + |
| 238 | +/* Internal precision in gains computation, e.g. Q4.28 in int32_t */ |
| 239 | +#define DMIC_FIR_SCALE_Q 28 |
| 240 | + |
| 241 | +#endif /* __DMIC_MACROS_H */ |
0 commit comments