39
39
#include "host_copier.h"
40
40
#include "dai_copier.h"
41
41
#include "ipcgtw_copier.h"
42
+ #if CONFIG_INTEL_ADSP_MIC_PRIVACY
43
+ #include <zephyr/drivers/mic_privacy/intel/mic_privacy.h>
44
+ #endif
42
45
43
46
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
44
47
#include <zephyr/drivers/dai.h>
@@ -51,6 +54,79 @@ SOF_DEFINE_REG_UUID(copier);
51
54
52
55
DECLARE_TR_CTX (copier_comp_tr , SOF_UUID (copier_uuid ), LOG_LEVEL_INFO );
53
56
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
+
54
130
static int copier_init (struct processing_module * mod )
55
131
{
56
132
union ipc4_connector_node_id node_id ;
@@ -131,6 +207,16 @@ static int copier_init(struct processing_module *mod)
131
207
comp_err (dev , "unable to create host" );
132
208
goto error ;
133
209
}
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
134
220
break ;
135
221
case ipc4_hda_link_output_class :
136
222
case ipc4_hda_link_input_class :
@@ -144,6 +230,15 @@ static int copier_init(struct processing_module *mod)
144
230
comp_err (dev , "unable to create dai" );
145
231
goto error ;
146
232
}
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
147
242
break ;
148
243
#if CONFIG_IPC4_GATEWAY
149
244
case ipc4_ipc_output_class :
@@ -184,6 +279,10 @@ static int copier_free(struct processing_module *mod)
184
279
struct copier_data * cd = module_get_private_data (mod );
185
280
struct comp_dev * dev = mod -> dev ;
186
281
282
+ #if CONFIG_INTEL_ADSP_MIC_PRIVACY
283
+ mic_privacy_free (cd );
284
+ #endif
285
+
187
286
switch (dev -> ipc_config .type ) {
188
287
case SOF_COMP_HOST :
189
288
if (!cd -> ipc_gtw )
0 commit comments