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,69 @@ 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+ #endif
119+
54120static int copier_init (struct processing_module * mod )
55121{
56122 union ipc4_connector_node_id node_id ;
@@ -131,6 +197,16 @@ static int copier_init(struct processing_module *mod)
131197 comp_err (dev , "unable to create host" );
132198 goto error ;
133199 }
200+ #if CONFIG_INTEL_ADSP_MIC_PRIVACY
201+ if (cd -> direction == SOF_IPC_STREAM_CAPTURE &&
202+ node_id .f .dma_type == ipc4_hda_host_output_class ) {
203+ ret = mic_privacy_configure (dev , cd );
204+ if (ret < 0 ) {
205+ comp_err (dev , "unable to configure mic privacy" );
206+ goto error ;
207+ }
208+ }
209+ #endif
134210 break ;
135211 case ipc4_hda_link_output_class :
136212 case ipc4_hda_link_input_class :
@@ -144,6 +220,15 @@ static int copier_init(struct processing_module *mod)
144220 comp_err (dev , "unable to create dai" );
145221 goto error ;
146222 }
223+ #if CONFIG_INTEL_ADSP_MIC_PRIVACY
224+ if (cd -> direction == SOF_IPC_STREAM_CAPTURE ) {
225+ ret = mic_privacy_configure (dev , cd );
226+ if (ret < 0 ) {
227+ comp_err (dev , "unable to configure mic privacy" );
228+ goto error ;
229+ }
230+ }
231+ #endif
147232 break ;
148233#if CONFIG_IPC4_GATEWAY
149234 case ipc4_ipc_output_class :
@@ -198,7 +283,9 @@ static int copier_free(struct processing_module *mod)
198283 default :
199284 break ;
200285 }
201-
286+ #if CONFIG_INTEL_ADSP_MIC_PRIVACY
287+ rfree (cd -> mic_priv );
288+ #endif
202289 if (cd )
203290 rfree (cd -> gtw_cfg );
204291 rfree (cd );
0 commit comments