Skip to content

Commit 4f8cf51

Browse files
singalsulgirdwood
authored andcommitted
Drivers: Intel: DMIC: Add NHLT binary data based configuration
This patch adds to DMIC driver support for binary data based HW registers setup. The driver mode is selected in Kconfig. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent ccd7bcb commit 4f8cf51

6 files changed

Lines changed: 669 additions & 35 deletions

File tree

src/drivers/intel/Kconfig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,35 @@ config INTEL_DMIC
4949

5050
if INTEL_DMIC
5151

52+
choice
53+
prompt "Driver operation mode"
54+
default INTEL_DMIC_TPLG_PARAMS
55+
help
56+
The driver can support two operation modes.
57+
- A HW registers dump blob that is passed via IPC
58+
- DAI tokens those describe the use case PCM format
59+
and PDM bus and microphone parameters
60+
61+
config INTEL_DMIC_NHLT
62+
bool "Use NHLT DMIC blob"
63+
help
64+
All registers configuration is retrieved from blob. The
65+
number of channels, sample rate, and PCM format are
66+
defined in the blob and there are no runtime made
67+
configuration choices.
68+
69+
config INTEL_DMIC_TPLG_PARAMS
70+
bool "Use parameters from topology"
71+
help
72+
All registers confifguration is computed on the fly
73+
based on use case and microphone datasheet parameters
74+
and topology defined PCM format. The parameters are
75+
easy to to customize in the topology.
76+
77+
endchoice
78+
79+
if INTEL_DMIC_TPLG_PARAMS
80+
5281
choice
5382
prompt "FIR decimation coefficients set"
5483
default INTEL_DMIC_FIR_FULL
@@ -167,4 +196,6 @@ config INTEL_DMIC_FIR_DECIMATE_BY_12
167196

168197
endmenu # "Decimation factors"
169198

199+
endif
200+
170201
endif # INTEL_DMIC
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22

3-
add_local_sources(sof dmic.c dmic_computed.c)
3+
add_local_sources(sof dmic.c)
4+
if(CONFIG_INTEL_DMIC_TPLG_PARAMS)
5+
add_local_sources(sof dmic_computed.c)
6+
endif()
7+
8+
if(CONFIG_INTEL_DMIC_NHLT)
9+
add_local_sources(sof dmic_nhlt.c)
10+
endif()

src/drivers/intel/dmic/dmic.c

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -137,47 +137,53 @@ static enum task_state dmic_work(void *data)
137137
static int dmic_get_hw_params(struct dai *dai,
138138
struct sof_ipc_stream_params *params, int dir)
139139
{
140+
#if CONFIG_INTEL_DMIC_TPLG_PARAMS
140141
return dmic_get_hw_params_computed(dai, params, dir);
142+
143+
#elif CONFIG_INTEL_DMIC_NHLT
144+
return dmic_get_hw_params_nhlt(dai, params, dir);
145+
146+
#else
147+
return -EINVAL;
148+
#endif
141149
}
142150

143-
static int dmic_set_config(struct dai *dai, struct ipc_config_dai *common_config,
144-
void *spec_config)
151+
static int dmic_set_config(struct dai *dai, struct ipc_config_dai *common_config, void *spec_config)
145152
{
146153
struct dmic_pdata *dmic = dai_get_drvdata(dai);
147-
struct sof_ipc_dai_config *config = spec_config;
148154
int32_t unmute_ramp_time_ms;
149155
int32_t step_db;
150-
int i;
151-
int j;
152156
int ret = 0;
153157
int di = dai->index;
158+
#if CONFIG_INTEL_DMIC_TPLG_PARAMS
159+
struct sof_ipc_dai_config *config = spec_config;
160+
int i;
161+
int j;
162+
#endif
154163

155164
dai_info(dai, "dmic_set_config()");
156165

157-
if (config->dmic.driver_ipc_version != DMIC_IPC_VERSION) {
158-
dai_err(dai, "dmic_set_config(): wrong ipc version");
166+
if (di >= DMIC_HW_FIFOS) {
167+
dai_err(dai, "dmic_set_config(): DAI index exceeds number of FIFOs");
168+
return -EINVAL;
169+
}
170+
171+
if (!spec_config) {
172+
dai_err(dai, "dmic_set_config(): NULL config");
159173
return -EINVAL;
160174
}
161175

176+
assert(dmic);
162177
spin_lock(&dai->lock);
163178

164-
/* Compute unmute ramp gain update coefficient. Use the value from
165-
* topology if it is non-zero, otherwise use default length.
179+
#if CONFIG_INTEL_DMIC_TPLG_PARAMS
180+
/*
181+
* "config" might contain pdm controller params for only
182+
* the active controllers
183+
* "prm" is initialized with default params for all HW controllers
166184
*/
167-
if (config->dmic.unmute_ramp_time)
168-
unmute_ramp_time_ms = config->dmic.unmute_ramp_time;
169-
else
170-
unmute_ramp_time_ms = dmic_get_unmute_ramp_from_samplerate(config->dmic.fifo_fs);
171-
172-
if (unmute_ramp_time_ms < LOGRAMP_TIME_MIN_MS ||
173-
unmute_ramp_time_ms > LOGRAMP_TIME_MAX_MS) {
174-
dai_err(dai, "dmic_set_config(): Illegal ramp time = %d", unmute_ramp_time_ms);
175-
ret = -EINVAL;
176-
goto out;
177-
}
178-
179-
if (di >= DMIC_HW_FIFOS) {
180-
dai_err(dai, "dmic_set_config(): dai->index exceeds number of FIFOs");
185+
if (config->dmic.driver_ipc_version != DMIC_IPC_VERSION) {
186+
dai_err(dai, "dmic_set_config(): wrong ipc version");
181187
ret = -EINVAL;
182188
goto out;
183189
}
@@ -188,17 +194,20 @@ static int dmic_set_config(struct dai *dai, struct ipc_config_dai *common_config
188194
goto out;
189195
}
190196

191-
step_db = LOGRAMP_CONST_TERM / unmute_ramp_time_ms;
192-
dmic->gain_coef = db2lin_fixed(step_db);
193-
dai_info(dai, "dmic_set_config(): unmute_ramp_time_ms = %d",
194-
unmute_ramp_time_ms);
195-
196-
/*
197-
* "config" might contain pdm controller params for only
198-
* the active controllers
199-
* "prm" is initialized with default params for all HW controllers
197+
/* Get unmute gain ramp duration. Use the value from topology
198+
* if it is non-zero, otherwise use default length.
200199
*/
201-
assert(dmic);
200+
if (config->dmic.unmute_ramp_time)
201+
unmute_ramp_time_ms = config->dmic.unmute_ramp_time;
202+
else
203+
unmute_ramp_time_ms = dmic_get_unmute_ramp_from_samplerate(config->dmic.fifo_fs);
204+
205+
if (unmute_ramp_time_ms < LOGRAMP_TIME_MIN_MS ||
206+
unmute_ramp_time_ms > LOGRAMP_TIME_MAX_MS) {
207+
dai_err(dai, "dmic_set_config(): Illegal ramp time = %d", unmute_ramp_time_ms);
208+
ret = -EINVAL;
209+
goto out;
210+
}
202211

203212
/* Copy the new DMIC params header (all but not pdm[]) to persistent.
204213
* The last arrived request determines the parameters.
@@ -223,6 +232,26 @@ static int dmic_set_config(struct dai *dai, struct ipc_config_dai *common_config
223232
}
224233

225234
ret = dmic_set_config_computed(dai);
235+
236+
#elif CONFIG_INTEL_DMIC_NHLT
237+
ret = dmic_set_config_nhlt(dai, spec_config);
238+
239+
/* There's no unmute ramp duration in blob, so the default rate dependent is used. */
240+
unmute_ramp_time_ms = dmic_get_unmute_ramp_from_samplerate(dmic->dai_rate);
241+
#else
242+
ret = -EINVAL;
243+
#endif
244+
245+
if (ret < 0) {
246+
dai_err(dai, "dmic_set_config(): Failed to set the requested configuration.");
247+
goto out;
248+
}
249+
250+
/* Compute unmute ramp gain update coefficient. */
251+
step_db = LOGRAMP_CONST_TERM / unmute_ramp_time_ms;
252+
dmic->gain_coef = db2lin_fixed(step_db);
253+
dai_info(dai, "dmic_set_config(): unmute_ramp_time_ms = %d", unmute_ramp_time_ms);
254+
226255
dmic->state = COMP_STATE_PREPARE;
227256

228257
out:

0 commit comments

Comments
 (0)