3939#include "host_copier.h"
4040#include "dai_copier.h"
4141#include "ipcgtw_copier.h"
42+ #if CONFIG_INTEL_ADSP_MIC_PRIVACY
43+ #include <zephyr/drivers/mic_privacy/intel/mic_privacy.h>
44+ #endif
4245
4346#if CONFIG_ZEPHYR_NATIVE_DRIVERS
4447#include <zephyr/drivers/dai.h>
@@ -51,6 +54,79 @@ SOF_DEFINE_REG_UUID(copier);
5154
5255DECLARE_TR_CTX (copier_comp_tr , SOF_UUID (copier_uuid ), LOG_LEVEL_INFO );
5356
57+ #if CONFIG_INTEL_ADSP_MIC_PRIVACY
58+ static void mic_privacy_event (void * arg , enum notify_id type , void * data )
59+ {
60+ struct mic_privacy_data * mic_priv_data = arg ;
61+ struct mic_privacy_settings * mic_privacy_settings = data ;
62+
63+ if (type == NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE ) {
64+ LOG_INF ("mic_privacy_event, state1 = %d, state2 = %d " ,
65+ mic_privacy_settings -> mic_privacy_state , mic_priv_data -> mic_privacy_state );
66+
67+ if (mic_privacy_settings -> mic_privacy_state == MIC_PRIV_UNMUTED ) {
68+ if (mic_priv_data -> mic_privacy_state == MIC_PRIV_MUTED ) {
69+ mic_priv_data -> mic_privacy_state = MIC_PRIV_FADE_IN ;
70+ LOG_INF ("mic_privacy_event switch to FADE_IN" );
71+ }
72+ } else {
73+ /* In case when mute would be triggered before copier instantiation. */
74+ if (mic_priv_data -> mic_privacy_state != MIC_PRIV_MUTED ) {
75+ mic_priv_data -> mic_privacy_state = MIC_PRIV_FADE_OUT ;
76+ LOG_INF ("mic_privacy_event switch to FADE_OUT" );
77+ }
78+ }
79+ mic_priv_data -> max_ramp_time_in_ms = (mic_privacy_settings -> max_ramp_time * 1000 ) /
80+ ADSP_RTC_FREQUENCY ;
81+ }
82+ }
83+
84+ static int mic_privacy_configure (struct comp_dev * dev , struct copier_data * cd )
85+ {
86+ struct mic_privacy_data * mic_priv_data ;
87+ int ret ;
88+
89+ mic_priv_data = rzalloc (SOF_MEM_ZONE_RUNTIME , 0 , SOF_MEM_CAPS_RAM ,
90+ sizeof (struct mic_privacy_data ));
91+ if (!mic_priv_data )
92+ return - ENOMEM ;
93+
94+ if (cd -> gtw_type == ipc4_gtw_dmic )
95+ mic_privacy_enable_dmic_irq (true);
96+
97+ mic_priv_data -> audio_freq = cd -> config .base .audio_fmt .sampling_frequency ;
98+
99+ uint32_t zeroing_wait_time = (mic_privacy_get_dma_zeroing_wait_time () * 1000 ) /
100+ ADSP_RTC_FREQUENCY ;
101+
102+ ret = copier_gain_set_params (dev , & mic_priv_data -> mic_priv_gain_params ,
103+ zeroing_wait_time , SOF_DAI_INTEL_NONE );
104+ if (ret != 0 ) {
105+ rfree (mic_priv_data );
106+ return ret ;
107+ }
108+
109+ cd -> mic_priv = mic_priv_data ;
110+
111+ ret = notifier_register (cd -> mic_priv , NULL , NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE ,
112+ mic_privacy_event , 0 );
113+ if (ret != 0 )
114+ rfree (mic_priv_data );
115+
116+ return ret ;
117+ }
118+
119+ static void mic_privacy_free (struct copier_data * cd )
120+ {
121+ if (cd -> gtw_type == ipc4_gtw_dmic )
122+ mic_privacy_enable_dmic_irq (false);
123+
124+ notifier_unregister (cd -> mic_priv , NULL , NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE );
125+
126+ rfree (cd -> mic_priv );
127+ }
128+ #endif
129+
54130static int copier_init (struct processing_module * mod )
55131{
56132 union ipc4_connector_node_id node_id ;
@@ -131,6 +207,16 @@ static int copier_init(struct processing_module *mod)
131207 comp_err (dev , "unable to create host" );
132208 goto error ;
133209 }
210+ #if CONFIG_INTEL_ADSP_MIC_PRIVACY
211+ if (cd -> direction == SOF_IPC_STREAM_CAPTURE &&
212+ node_id .f .dma_type == ipc4_hda_host_output_class ) {
213+ ret = mic_privacy_configure (dev , cd );
214+ if (ret < 0 ) {
215+ comp_err (dev , "unable to configure mic privacy" );
216+ goto error ;
217+ }
218+ }
219+ #endif
134220 break ;
135221 case ipc4_hda_link_output_class :
136222 case ipc4_hda_link_input_class :
@@ -144,6 +230,15 @@ static int copier_init(struct processing_module *mod)
144230 comp_err (dev , "unable to create dai" );
145231 goto error ;
146232 }
233+ #if CONFIG_INTEL_ADSP_MIC_PRIVACY
234+ if (cd -> direction == SOF_IPC_STREAM_CAPTURE ) {
235+ ret = mic_privacy_configure (dev , cd );
236+ if (ret < 0 ) {
237+ comp_err (dev , "unable to configure mic privacy" );
238+ goto error ;
239+ }
240+ }
241+ #endif
147242 break ;
148243#if CONFIG_IPC4_GATEWAY
149244 case ipc4_ipc_output_class :
@@ -184,6 +279,10 @@ static int copier_free(struct processing_module *mod)
184279 struct copier_data * cd = module_get_private_data (mod );
185280 struct comp_dev * dev = mod -> dev ;
186281
282+ #if CONFIG_INTEL_ADSP_MIC_PRIVACY
283+ mic_privacy_free (cd );
284+ #endif
285+
187286 switch (dev -> ipc_config .type ) {
188287 case SOF_COMP_HOST :
189288 if (!cd -> ipc_gtw )
0 commit comments