Drivers: Intel: DMIC: Separate decimation filters setup computation

This patch moves the run-time decimation factors search and filter
coefficients scaling code to separate module as preparation to add
more functionality to the driver. There are no changes to
functionality.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This commit is contained in:
Seppo Ingalsuo 2021-04-12 17:58:44 +03:00 committed by Liam Girdwood
parent 922cb6af7c
commit c5f50f533f
5 changed files with 1100 additions and 1059 deletions

View File

@ -1,3 +1,3 @@
# SPDX-License-Identifier: BSD-3-Clause
add_local_sources(sof dmic.c)
add_local_sources(sof dmic.c dmic_computed.c)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,23 @@
#if CONFIG_INTEL_DMIC
/* Let find up to 50 mode candidates to choose from */
#define DMIC_MAX_MODES 50
/* Minimum OSR is always applied for 48 kHz and less sample rates */
#define DMIC_MIN_OSR 50
/* These are used as guideline for configuring > 48 kHz sample rates. The
* minimum OSR can be relaxed down to 40 (use 3.84 MHz clock for 96 kHz).
*/
#define DMIC_HIGH_RATE_MIN_FS 64000
#define DMIC_HIGH_RATE_OSR_MIN 40
/* HW FIR pipeline needs 5 additional cycles per channel for internal
* operations. This is used in MAX filter length check.
*/
#define DMIC_FIR_PIPELINE_OVERHEAD 5
/* The microphones create a low frequecy thump sound when clock is enabled.
* The unmute linear gain ramp chacteristic is defined here.
* NOTE: Do not set any of these to 0.
@ -313,9 +330,38 @@
#define FIR_COEF_A(x) SET_BITS(19, 0, x)
#define FIR_COEF_B(x) SET_BITS(19, 0, x)
/* Used for scaling FIR coefficients for HW */
#define DMIC_HW_FIR_COEF_MAX ((1 << (DMIC_HW_BITS_FIR_COEF - 1)) - 1)
#define DMIC_HW_FIR_COEF_Q (DMIC_HW_BITS_FIR_COEF - 1)
/* Internal precision in gains computation, e.g. Q4.28 in int32_t */
#define DMIC_FIR_SCALE_Q 28
/* Used in unmute ramp values calculation */
#define DMIC_HW_FIR_GAIN_MAX ((1 << (DMIC_HW_BITS_FIR_GAIN - 1)) - 1)
/* Hardwired log ramp parameters. The first value is the initial gain in
* decibels. The second value is the default ramp time.
*/
#define LOGRAMP_START_DB Q_CONVERT_FLOAT(-90, DB2LIN_FIXED_INPUT_QY)
#define LOGRAMP_TIME_MS 400 /* Default ramp time in milliseconds */
/* Limits for ramp time from topology */
#define LOGRAMP_TIME_MIN_MS 10 /* Min. 10 ms */
#define LOGRAMP_TIME_MAX_MS 1000 /* Max. 1s */
/* Simplify log ramp step calculation equation with this constant term */
#define LOGRAMP_CONST_TERM ((int32_t) \
((int64_t)-LOGRAMP_START_DB * DMIC_UNMUTE_RAMP_US / 1000))
/* Fractional shift for gain update. Gain format is Q2.30. */
#define Q_SHIFT_GAIN_X_GAIN_COEF \
(Q_SHIFT_BITS_32(30, DB2LIN_FIXED_OUTPUT_QY, 30))
#define dmic_irq(dmic) dmic->plat_data.irq
#define dmic_irq_name(dmic) dmic->plat_data.irq_name
/* Common data for all DMIC DAI instances */
struct dmic_global_shared {
struct sof_ipc_dai_dmic_params prm[DMIC_HW_FIFOS]; /* Configuration requests */
uint32_t active_fifos_mask; /* Bits (dai->index) are set to indicate active FIFO */
@ -335,6 +381,40 @@ struct dmic_pdata {
};
struct decim_modes {
int16_t clkdiv[DMIC_MAX_MODES];
int16_t mcic[DMIC_MAX_MODES];
int16_t mfir[DMIC_MAX_MODES];
int num_of_modes;
};
struct matched_modes {
int16_t clkdiv[DMIC_MAX_MODES];
int16_t mcic[DMIC_MAX_MODES];
int16_t mfir_a[DMIC_MAX_MODES];
int16_t mfir_b[DMIC_MAX_MODES];
int num_of_modes;
};
struct dmic_configuration {
struct pdm_decim *fir_a;
struct pdm_decim *fir_b;
int clkdiv;
int mcic;
int mfir_a;
int mfir_b;
int cic_shift;
int fir_a_shift;
int fir_b_shift;
int fir_a_length;
int fir_b_length;
int32_t fir_a_scale;
int32_t fir_b_scale;
};
int dmic_set_config_computed(struct dai *dai);
int dmic_get_hw_params_computed(struct dai *dai, struct sof_ipc_stream_params *params, int dir);
extern const struct dai_driver dmic_driver;
#endif /* DMIC_HW_VERSION */

View File

@ -154,6 +154,7 @@ if (CONFIG_SOC_SERIES_INTEL_CAVS_V15)
zephyr_library_sources_ifdef(CONFIG_INTEL_DMIC
${SOF_DRIVERS_PATH}/intel/dmic/dmic.c
${SOF_DRIVERS_PATH}/intel/dmic/dmic_computed.c
)
# Platform sources
@ -207,6 +208,7 @@ if (CONFIG_SOC_SERIES_INTEL_CAVS_V18)
zephyr_library_sources_ifdef(CONFIG_INTEL_DMIC
${SOF_DRIVERS_PATH}/intel/dmic/dmic.c
${SOF_DRIVERS_PATH}/intel/dmic/dmic_computed.c
)
# Platform sources
@ -262,6 +264,7 @@ if (CONFIG_SOC_SERIES_INTEL_CAVS_V20)
zephyr_library_sources_ifdef(CONFIG_INTEL_DMIC
${SOF_DRIVERS_PATH}/intel/dmic/dmic.c
${SOF_DRIVERS_PATH}/intel/dmic/dmic_computed.c
)
# Platform sources
@ -319,6 +322,7 @@ if (CONFIG_SOC_SERIES_INTEL_CAVS_V25)
zephyr_library_sources_ifdef(CONFIG_INTEL_DMIC
${SOF_DRIVERS_PATH}/intel/dmic/dmic.c
${SOF_DRIVERS_PATH}/intel/dmic/dmic_computed.c
)
# Platform sources