Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions src/audio/copier/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,33 @@ LOG_MODULE_REGISTER(copier, CONFIG_SOF_LOG_LEVEL);
SOF_DEFINE_REG_UUID(copier);

#if CONFIG_INTEL_ADSP_MIC_PRIVACY
static void mic_privacy_event(void *arg, enum notify_id type, void *data)
/* Take the mic privacy state posted since the last copy, see mic_privacy_propagate_settings() */
static void mic_privacy_take_state(struct mic_privacy_data *mic_priv_data)
{
struct mic_privacy_data *mic_priv_data = arg;
struct mic_privacy_settings *mic_privacy_settings = data;
uint32_t word = atomic_get(&mic_privacy_state_word);

if (type == NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE) {
LOG_INF("state1 = %d, state2 = %d ",
mic_privacy_settings->mic_privacy_state, mic_priv_data->mic_privacy_state);
if (MIC_PRIV_STATE_SEQ(word) == mic_priv_data->state_seq)
return;

if (mic_privacy_settings->mic_privacy_state == MIC_PRIV_UNMUTED) {
if (mic_priv_data->mic_privacy_state == MIC_PRIV_MUTED) {
mic_priv_data->mic_privacy_state = MIC_PRIV_FADE_IN;
LOG_INF("switch to FADE_IN");
}
} else {
/* In case when mute would be triggered before copier instantiation. */
if (mic_priv_data->mic_privacy_state != MIC_PRIV_MUTED) {
mic_priv_data->mic_privacy_state = MIC_PRIV_FADE_OUT;
LOG_INF("switch to FADE_OUT");
}
mic_priv_data->state_seq = MIC_PRIV_STATE_SEQ(word);

LOG_INF("state1 = %u, state2 = %d ",
MIC_PRIV_STATE_MUTE(word), mic_priv_data->mic_privacy_state);

if (!MIC_PRIV_STATE_MUTE(word)) {
if (mic_priv_data->mic_privacy_state == MIC_PRIV_MUTED) {
mic_priv_data->mic_privacy_state = MIC_PRIV_FADE_IN;
LOG_INF("switch to FADE_IN");
}
} else {
/* In case when mute would be triggered before copier instantiation. */
if (mic_priv_data->mic_privacy_state != MIC_PRIV_MUTED) {
mic_priv_data->mic_privacy_state = MIC_PRIV_FADE_OUT;
LOG_INF("switch to FADE_OUT");
}
mic_priv_data->max_ramp_time_in_ms = (mic_privacy_settings->max_ramp_time * 1000) /
ADSP_RTC_FREQUENCY;
}
mic_priv_data->max_ramp_time_in_ms = (MIC_PRIV_STATE_RAMP(word) * 1000) /
ADSP_RTC_FREQUENCY;
}

__cold static int mic_privacy_configure(struct processing_module *mod, struct copier_data *cd)
Expand Down Expand Up @@ -111,13 +114,10 @@ __cold static int mic_privacy_configure(struct processing_module *mod, struct co

cd->mic_priv = mic_priv_data;

ret = notifier_register(cd->mic_priv, NULL, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE,
mic_privacy_event);
/* only take the mic privacy states posted from now on */
mic_priv_data->state_seq = MIC_PRIV_STATE_SEQ(atomic_get(&mic_privacy_state_word));

if (ret != 0)
mod_free(mod, mic_priv_data);

return ret;
return 0;
}

__cold static void mic_privacy_free(struct processing_module *mod)
Expand All @@ -129,8 +129,6 @@ __cold static void mic_privacy_free(struct processing_module *mod)
if (cd->gtw_type == ipc4_gtw_dmic)
mic_privacy_enable_dmic_irq(false);

notifier_unregister(cd->mic_priv, NULL, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE);

mod_free(mod, cd->mic_priv);
}
#endif
Expand Down Expand Up @@ -818,6 +816,11 @@ static int copier_process(struct processing_module *mod,

comp_dbg(dev, "entry");

#if CONFIG_INTEL_ADSP_MIC_PRIVACY
if (cd->mic_priv)
mic_privacy_take_state(cd->mic_priv);
#endif

switch (dev->ipc_config.type) {
case SOF_COMP_HOST:
if (!cd->ipc_gtw)
Expand Down
19 changes: 18 additions & 1 deletion src/include/sof/audio/mic_privacy_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,35 @@
#define ADSP_FW_MIC_PRIVACY_MANAGER_H

#include <zephyr/drivers/mic_privacy/intel/mic_privacy.h>
#include <sof/lib/notifier.h>
#include <zephyr/sys/atomic.h>
#include <ipc4/base-config.h>
#include "../audio/copier/copier_gain.h"

#define ADSP_RTC_FREQUENCY 32768

/*
* The mic privacy state for the copiers is a single word, so that the kernel
* can post it from the mic privacy interrupts and IPC, and the copiers can
* read it in their LL threads without a lock: an 8-bit sequence number, the
* mic disable state and the DMA data zeroing wait time in RTC ticks.
*/
#define MIC_PRIV_STATE_WORD(seq, mute, ramp) ((((uint32_t)(seq) & 0xff) << 24) | \
((uint32_t)!!(mute) << 16) | \
((uint32_t)(ramp) & 0xffff))
#define MIC_PRIV_STATE_SEQ(word) (((uint32_t)(word) >> 24) & 0xff)
#define MIC_PRIV_STATE_MUTE(word) (((uint32_t)(word) >> 16) & 0x1)
#define MIC_PRIV_STATE_RAMP(word) ((uint32_t)(word) & 0xffff)

/* the last mic privacy state, posted by mic_privacy_propagate_settings() */
extern atomic_t mic_privacy_state_word;

struct mic_privacy_data {
enum ipc4_sampling_frequency audio_freq;
uint32_t mic_privacy_state;
bool dma_data_zeroing;
uint32_t fade_in_out_bytes;
uint32_t max_ramp_time_in_ms;
uint8_t state_seq; /**< sequence number of the last mic privacy state taken */

struct copier_gain_params mic_priv_gain_params;
};
Expand Down
1 change: 0 additions & 1 deletion src/include/sof/lib/notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ enum notify_id {
NOTIFIER_ID_DMA_COPY, /* struct dma_cb_data* */
NOTIFIER_ID_DMA_IRQ, /* struct dma_chan_data * */
NOTIFIER_ID_DAI_TRIGGER, /* struct dai_group * */
NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE, /* struct mic_privacy_settings * */
NOTIFIER_ID_VAD, /* int * (WEBRTC_VAD_SPEECH / WEBRTC_VAD_SILENCE) */
NOTIFIER_ID_COUNT
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sof/audio/buffer.h>
#include <sof/audio/mic_privacy_manager.h>
#include <sof/lib/memory.h>
#include <rtos/userspace_data.h>

const struct device *mic_priv_dev;

Expand Down Expand Up @@ -126,11 +127,24 @@ uint32_t mic_privacy_get_policy_register(void)
return mic_privacy_api->get_privacy_policy_register_raw_value();
}

/*
* Kernel code writes it, the copiers read it in the LL threads, which can be
* user threads.
*/
APP_SYSUSER_BSS atomic_t mic_privacy_state_word;

/* Post the mic privacy state for the copiers, which take it in their next copy. */
void mic_privacy_propagate_settings(struct mic_privacy_settings *settings)
{
notifier_event(mic_priv_dev, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE,
NOTIFIER_TARGET_CORE_ALL_MASK, settings,
sizeof(struct mic_privacy_settings));
atomic_val_t old;
atomic_val_t new;

do {
old = atomic_get(&mic_privacy_state_word);
new = MIC_PRIV_STATE_WORD(MIC_PRIV_STATE_SEQ(old) + 1,
settings->mic_privacy_state,
settings->max_ramp_time);
} while (!atomic_cas(&mic_privacy_state_word, old, new));
}

uint32_t mic_privacy_get_dma_zeroing_wait_time(void)
Expand Down
Loading